I am working on a program to control a VFD using a USB to RS485 adaptor.
I was having issues in which the VFD would simply blink momentarily when I would try to send a command.
To check deeper, I figured I would test my USB to RS485 converter by running a loop-back test (wiring the transmission pins to the recieving pins, and checking to see if the data sent is also recieved.
Using various serial testing applications, I was able to verify that it worked. I would send data, and it would show that it both sent and recieved.
However, it doesn't work for the program I am writing. When the program starts up, I get a few sent/recieved signals that say ".enq.". However, when the program runs, it shows that data is sent, but it never shows that it was recieved. I wasn't sure if it was an error in how I had my serial port set up.
Here is my setup code.
public MITCOM(IniFile INI_in)
{
itsINI = INI_in;
itsName = itsINI.ReadCheckDefault("MITSUBISHI", "Port", "COM4");
itsBaudRate = Convert.ToInt16(itsINI.ReadCheckDefault("MITSUBISHI", "BaudRate", "19200"));
itsDataBits = Convert.ToInt16(itsINI.ReadCheckDefault("MITSUBISHI", "DataBits", "8"));
switch (itsINI.ReadCheckDefault("MITSUBISHI", "Parity", "Even"))
{
case "Even":
itsParity = Parity.Even;
break;
case "Odd":
itsParity = Parity.Odd;
break;
default:
itsParity = Parity.Even;
itsINI.WriteValue("MITSUBISHI", "Parity", "Even");
break;
}
switch(itsINI.ReadCheckDefault("MITSUBISHI", "StopBits", "2"))
{
case "1":
itsStopBits = StopBits.One;
break;
case "2":
itsStopBits = StopBits.Two;
break;
default:
itsStopBits = StopBits.Two;
itsINI.WriteValue("MITSUBISHI", "StopBits", "2");
break;
}
itsPort = new SerialPort(itsName, itsBaudRate, itsParity, 8, itsStopBits);
itsPort.Open();
And here is the code it uses to send a message:
public void A1(string _instruction, byte WAIT, Int16 Data)
{
var Bytes = new List<byte>();
Bytes.Add(Control_Code.ENQ);
Bytes.AddRange(Encoding.ASCII.GetBytes("00"));
Bytes.AddRange(Encoding.ASCII.GetBytes(_instruction));
Bytes.AddRange(Encoding.ASCII.GetBytes(WAIT.ToString("X")));
Bytes.AddRange(Encoding.ASCII.GetBytes(Data.ToString("X2")));
int SUM = 0;
for(int i = 1; i < 8; i++)
{
SUM += Bytes[i];
}
SUM &= 0xFF;
Bytes.AddRange(Encoding.ASCII.GetBytes(SUM.ToString("X2")));
Bytes.Add(Control_Code.CR);
itsPort.Write(Bytes.ToArray(), 0, 11);
}
To reiterate:
-Loopback tests succeed when sent through 3rd party software (free device monitoring studio (FDMS)) -When booting up MY software, I get a few .enq. messages. -When my program tries to send data, FDMS show that data was sent, but was not recieved.
Any help you guys can give will be greatly appreciated!