小编Mar*_*nez的帖子

从Android向PLC发送布尔值

我能够与PLC建立连接以从中读取数据.现在有一个问题,那就是我必须编写一个方法来修改PLC中的数据.为此,我必须向PLC发送两个值:int值和布尔值.我通过net.wimpi.modbus包中的类解决了int值.但是当谈到布尔值时,我不知道该怎么做.

如果有人遇到和我现在一样的问题,你能不能给我一个参考资料,在那里我可以找到一个解决方案或一个非常好的教程链接来解决我的问题?有人在这个问题上贴了几个链接,但是它发给我的教程与PLC的通信以及如何处理PLC的数据没什么关系.

编辑

我与Modicon M340 PLC建立了连接,对于连接,我使用了net.wimpi.modbus包的类.我发过班,我的代码的连接ModbusTCPTransactionTCPMasterConnection,和我通过阅读类的价值观ReadMultipleRegistersRequestReadMultipleRegistersResponse.

我为连接编写的代码:

    private InetAddress m_Address;
private ModbusTCPTransaction m_Transaction = null;
private TCPMasterConnection m_Connection = null;

int port = Modbus.DEFAULT_PORT;
private Activity activity;


public ModbusConnection(Activity activity, String ip)
{
    this.activity = activity;

    try {
        m_Address = InetAddress.getByName(ip); 
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } // the slave'saddress
}

public void getTransaction(InetAddress inet) throws Exception
{
    /*Variables for the reading of the …
Run Code Online (Sandbox Code Playgroud)

java android boolean plc modbus

6
推荐指数
1
解决办法
3959
查看次数

按C#中的代码设置列表框项的字体和颜色

我正忙于一个自定义列表框,我在c#中用作注册阅读器.现在,我想在一个确定的项目中设置一个确定的项目,其中的字体和颜色与其他项目不同.我检查了这个问题,并从答案中我做了以下代码:

private void myListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
    e.DrawBackground();
    Font myFont;
    Brush myBrush;
    int i = e.Index;

    if (e.Index == 3)
    {
        myFont = e.Font;
        myBrush = Brushes.Black;
    }
    else
    {
        myFont = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold);
        myBrush = Brushes.CadetBlue;
    }

    e.Graphics.DrawString(myListBox.Items[i].ToString(), myFont, myBrush, e.Bounds, StringFormat.GenericDefault);
}
Run Code Online (Sandbox Code Playgroud)

并使用我的IntializeComponent()调用该方法

this.myListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.myListBox_DrawItem);
Run Code Online (Sandbox Code Playgroud)

该调用不会抛出任何异常,但我看到我想要处理的行没有变化.有什么我想念的吗?

c# listbox winforms

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

boolean ×1

c# ×1

java ×1

listbox ×1

modbus ×1

plc ×1

winforms ×1