Reputation: 1540
I'm currently writing an application to communicate with a device called a Fluke 5500A Multi-Product Calibrator. The manual for the calibrator includes a sample VB6 program using the following code:
Sub Form_Load ()
Comm1.CommPort = 1 [if using COM2, enter = 2]
Comm1.Settings = “9600,N,8,1” [baud, parity, data, stop]
Comm1.PortOpen = True
End Sub
Command Button 1:
Sub Command1_Click ()
Comm1.Output = “REMOTE” + Chr(10)
End Sub
Command Button 2:
Sub Command2_Click ()
Comm1.Output = “LOCAL” + Chr(10)
End Sub
Command Button 3:
Sub Command3_Click ()
Comm1.Output = “UUT_SEND ““<uut command>”” ” + Chr(10)
End Sub
There's a uut command example like so:
“UUT_SEND ““REMS\n””
My question is this. Is it possible to use the C# .Net 4.0 SerialPort class to achieve this communication? I've never attempted to use a serial port before and I'm extremely new to this but I have the following in C#:
Comm1.PortName = "COM1";
Comm1.BaudRate = 9600;
Comm1.Parity = System.IO.Ports.Parity.None;
Comm1.DataBits = 8;
Comm1.StopBits = System.IO.Ports.StopBits.One;
How do I set Comm1.Output like it's set in the sample program? Moreover what propery in SerialPort's class corresponds with that? Will what I'm attempting even work?
Upvotes: 2
Views: 1343
Reputation:
It is possible to use C# .Net 4.0 SerialPort class to achieve this communication.
Please see the following links for information and support.
This woman has written books (that I've used) and her forum is great for serial port communication. Everything you could possibly need is here:
http://www.lvr.com/forum/index.php
I also recommend the MSDN forum, as I find this very useful for .net.
http://social.msdn.microsoft.com/Forums/en-us/home
Here are some links to the MSDN for Serial Port Class with different frameworks.
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.90).aspx
It is impossible to cover the ins and outs of all the options with this type of coding. Various writeline, readline, readexisting, checking for bytes to read, etc permutations, and it depends on the data being sent, whether carriage returns need to be included regularly.
I hope this has helped. I don't think this is the place to rewrite the code, but if you get stuck in certain places, I would certainly encourage you to post questions. Specific is better.
Upvotes: 3