c#

位置:IT落伍者 >> c# >> 浏览文章

c#通过网线读取三菱PLC数据


发布日期:2018年02月27日
 
c#通过网线读取三菱PLC数据

public static bool PlcWrite(int adres int count string SendData)

{

if (SysPlcComUse == )

return true;

string s_adres = (adres + SysPlcBaseAddress)ToString(#####);

string s_count = countToString(X)PadLeft( );

string hdr = FFFF;

string s_data = AD* + s_adres + s_count + SendData;

string n = (s_dataLengthToString(X))PadLeft( );

string dtfram = (hdr + n + s_data);

byte[] msg = EncodingASCIIGetBytes(dtfram);

plcComtxtSendText = ABC;

ApplicationDoEvents();

if (SysDeb != )

return true;

int byteSend = SockSend(msg);

SystemTextEncoding encoding = SystemTextEncodingUTF;

string smsg = encodingGetString(msg);

SystemDateTime Stime = DateTimeNow;

TimeSpan Ctime = new TimeSpan();

do

{

TimeSpan Ptime = (DateTimeNow Stime);

if (Ptime > Ctime)

{

MessageBoxShow(PLC comm time out error);

return false;

}

ApplicationDoEvents();

} while (SockAvailable == );

int byteRec = SockReceive(RcvBytes);

string rcvstr = SystemTextEncodingUTFGetString(RcvBytes);

plcComtxtRcvText = rcvstr;

string emsg = rcvstrSubstring( );

if (emsg != )

{

plcComtxtRcvText += error code + emsg;

MessageBoxShow(PLC comm data error + emsg);

}

return true;

}

读取PLC数据

view plainprint?

public static bool PlcRead(int adres int count ref string ReadData)

{

if (SysPlcComUse == )

return true;

PlcReadBusy = true;

string s_adres = (adres + SysPlcBaseAddress)ToString(#####);

string s_count = countToString(###);

string hdr = FFFF;

string s_data = AD* + s_adres + s_count;

string n = (s_dataLengthToString(X))PadLeft( );

string dtfram = (hdr + n + s_data);

byte[] msg = EncodingASCIIGetBytes(dtfram);

if (SysDeb != )

{

PlcReadBusy = false;

return true;

}

int byteSend = SockSend(msg);

SystemTextEncoding encoding = SystemTextEncodingUTF;

string smsg = encodingGetString(msg);

SystemDateTime Stime = DateTimeNow;

TimeSpan Ctime = new TimeSpan();

do

{

TimeSpan Ptime = (DateTimeNow Stime);

if (Ptime > Ctime)

{

MessageBoxShow(PLC comm time out error);

PlcReadBusy = false;

return false;

}

ApplicationDoEvents();

} while (SockAvailable == );

int byteRec = SockReceive(RcvBytes);

ReadData = SystemTextEncodingUTFGetString(RcvBytes);

plcComtxtRcvText = ReadData;

string emsg = ReadDataSubstring( );

if (emsg != )

{

plcComtxtRcvText += error code + emsg;

PlcReadBusy = false;

return false;

}

ReadData = ReadDataSubstring();

PlcReadBusy = false;

return true;

}

}

               

上一篇:ASP.net中用axWebBrowser中提交表单

下一篇:利用C#制作简单的留言板的方法