blueskit / MitsubishiPlcProtocol

三菱PLC(Mitsubishi)通讯协议的C#实现,支持FX、Q系列的ASCII-3E、BIN-3E、FX串口格式。
MIT License
296 stars 153 forks source link

Write on/off Y/M to PLC #6

Closed lacduong closed 6 years ago

lacduong commented 6 years ago

Dear Sir, I am using your source code to read and write from C# program to FX plc. I read the data from PLC Ok but when I try to write the Y0 bit is ON or OFF I don't know how I can use your source code When I try the following code but it fail !

cmd = FxCommandHelper.Make(FxCommandConst.FxCmdForceOn, new FxAddress("Y0")); // turn on Y0 res = FxSerial.Send(9, cmd); // com is 9 Debug.WriteLine(string.Format("Y0 \t{0}", res.ToString()));

Please kindly help me, Thank you very much

blueskit commented 6 years ago
  /// <summary>
    /// 执行命令,并返回执行的结果
    /// 读写PLC单元的字符串型命令格式如下:
    ///        excute("D126");                读单一元件值
    ///        excute("D126,2");            读连续2多个元件值
    ///        excute("M100,8");            读连续8个元件值
    ///        excute("M100..128");        读连续多个元件值(M100到M128)
    ///        excute("D10=135");            为单一元件赋值
    ///        excute("R053=1000");        为元件赋值
    ///        excute("M401=1");            为单一元件赋值
    ///        excute("D126,6=0");            为连续元件赋值
    ///        excute("D126..130=0");        为连续元件赋值
    ///        excute("R053,2=0");            为连续元件赋值
    /// </summary>
    /// <param name="plc"></param>
    /// <param name="cmdText">读写PLC单元的字符串型命令</param>
    public ResponseMessage Excute(string cmdText)
    {
        return _plc.Excute(cmdText);
    }

see up lines:

    excute("M401=1");          // write 1 to M401
    excute("Y0=1");              // write 1 to Y0
lacduong commented 6 years ago

Dear blueskit,

The command: Excute(string cmdText), I found in the Mitsubishi folder and this may be used for the FX plc uses the MC protocol with the Ethernet Port

I have the fx plc with a serial port, can I use the excute("M1=1") command in Serial FX PLC ?

image