I've been assigned to display weight from weighing scale (CAS CI-201A) into a textbox using C#. The weight will be sent via serial port RS-232 or USB converter. The scale is with me but I don't know where to start. How can I achieve my goal?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I was using Anto sujesh's Code, but I had the problem that some of the values I got from the scale were corrupted. I solved it by buffering the values in a cache file.
Firstly, before you start to code anything, I would check whether you're using the right cable. Try open a serial terminal of your choice (HyperTerm, putty) and check whether there is any data at all.
Be sure to configure the same baudrate, stopbits and parity on both the weight scale and your terminal program.
If you receive data (the terminal program should at least display some garbage), then you can move on to coding. If not, check if you're using the right cable (nullmodem aka crossed-over).
When you're this far, then you may use the
SerialPort
class of C# http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspxHave you tried anything yet?
If you want to use the serial port it makes sense to first give the user a way to select which port to use. This can be done easily, by filling a combobox with all available ports.
This code uses a form with a comboBox on it, called "comboBox1" (Default). You will need to add:
to the using directives.
Then add a button (button1) and a multiline textbox (textbox1) to the form and add this code:
This also requires you to add:
right below the opening brackets of
After clicking the button, all received data from the selected comPort will be displayed as hex values in the TextBox.
DISCLAIMER: The above code contains NO error-handling and will produce errors if button1 is clicked multiple times, due to the fact that the previous instance of "SerialPort" is not closed properly. Please remember this when using this example.
Regards Nico
Complete Code:
based on adam suggestion i converted the output to human readable format ( from ASCII to UTF8 ) i puts the bytes into an array byte[]
here is the full working code
if your are using A&D EK V Calibration Model : AND EK-610V. you have use BaudRate = 2400; and DataBits = 7
Note : if you get output like this
you have to check the BaudRate,DataBits (refer your weighing machine manual ) or check your cable