0

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!

user2596874
  • 63
  • 1
  • 1
  • 7
  • What is the message format for your device? You also need to verify your port settings with what your device is expecting. – Mark Hall Apr 27 '15 at 05:57
  • Yeah, the ReadCheckDefault() function checks to see if the value exists in the ini file. If it does, it reads it from the ini. if not, it uses the specified default value. The defaults are based on the default value of the VFD. Both have been verified to match. However, it still does not explain why the data sent is not also recieved when the adaptor is directly looped in on itself. – user2596874 Apr 27 '15 at 06:03
  • Don't rule out the USB adapter, I have have had problems with USB Adapters in the past, I usually use a serial port and a protocol converter on my systems. – Mark Hall Apr 27 '15 at 06:08
  • yeah, that's what I hear. I tried to choose this one based on the best reviews. – user2596874 Apr 27 '15 at 06:10

0 Answers0