I am trying to send some data to a LCD display that works over serial port. This code does the job over VB6 but i needed to convert it to C#. Sadly it does not work. Any ideas?
VB6 (Example)
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.Output = Chr(2)
MSComm1.Output = Trim(Text1.Text)
C# (Example)
var serialPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
serialPort1.Open();
serialPort1.Write(((char)2).ToString());
serialPort1.Write(textbox1.Text);
serialPort1.Close();
I think the problem is about serialPort1.Write function but i could not figure it out. Can you help please?
First, try this helper extension method to make writing one-byte control codes easier
Then change your code to this:
Please note that I didn’t syntax check this but just free-handed it so you might need to tweak it a bit.