|
Joseph,
could it be that the data simply is zero? You can double check with Wireshark what
data you request and what data you receive in the response. Also keep in mind that
coils are output data. If you want to read digital input data you have to use
discrete inputs.
Stephan
|
|
|
|
|
Stephan,
the function code returned in the answer can not be zero. It must be equal to 0x01 if there is no error or 0x81 if there is an error.
I do not understand why it is zero.
It seems that when the event OnReceive is fired, the tcpAsyClBuffer is not filled.
Joseph
|
|
|
|
|
Ok, I found the problem: everything is equal to zero because the slave didn't answer.
I modified the onReceive function (in modbus.cs) to detect it.
I used the following code:
int nBytesReceived;
nBytesReceived = tcpAsyCl.EndReceive(result);
if (nBytesReceived == 0)
{
CallException(0, 0, excExceptionTimeout);
return;
}
|
|
|
|
|
Hello.
I am Miguel, i am writting to ask about the ModbusTCP class.
I took several days trying to enterder your code.
When I put the IP of the device thtan i want to connect. The grpData grpExchange activated (visible = true), which means it was possible to communicate with the device. It's true.? ..
But when I put the address of the device, such as 400001, and give to the function read input register or holding register, in the textbox fields ... still nothing appears empty ...
I use a traditional SCADA demo to test the connection to the device and it is successful ... I think the problem is not the device
Could you please help me to understand what is happening.?
|
|
|
|
|
Hey There
I wanted to include your library with a sincronous threading. I'm not really getting an error but the problem is, that when I write a command get a response for it, write another one and get the same response for the first command I've written. Can you please help me fix this problem. I can't post much Code, because it's about 15'000 lines.
But I didn't changed anything of your library so please help me. I'm really getting crazy.. ^^
Greetings Farin
|
|
|
|
|
Farin,
the response to a write command is just the number of bytes that were written. So it makes sense that you get the same response if the number of bytes is the same.
Stephan
|
|
|
|
|
I'm sorry to correct you but the response you usually get is the transaction id, the function byte, an exception byte and in case of a read command some data bytes...
That's why I was wondering but I fixed the problem. My Porgram was too fast. It wrote into the buffer when it wasn't even written. ^^
So it's working now and everybody is happy.. yay =)
|
|
|
|
|
Hello,
I'm currently testing your modbus TCP application. How ever I get the following message: No connection could be made because the target machine actively refused it.
I entered 192.168.20.11 in the textfield as this is where it should connect to. Could anyone explain me what I do wrong?
My fire wall is turned off.
Kind regards,
Metroickha
|
|
|
|
|
This error message could mean that port is already in use and the slave is not allowing multiple connections or the slave is not running at all.
|
|
|
|
|
Hello,
Is it possible to communicate to slave devices from asp.net thru TCP?
Thank you
Chris
|
|
|
|
|
I am codding for an allan bradley micro logix 1400 plc. I'm using your class to code for the modbus tcp rtu protocol.
the problem is that the address are in the format N7 , N7:11, B3:200/0, etc. will these address work if i use them in the code or else, how am i supposed to map the adress??
|
|
|
|
|
I have stumbled upon this sample program "Modbus TCP class" and I would like to run it. What software to I need to run it? I have Visual Basic 2010 Express. Is that sufficient? I have done quite a lot of VB6 programming and have written a similar program. Any help to get me started would be most appreciated.
|
|
|
|
|
You need Visual C# to run the sample. The driver itself can run in any other .Net language
but you would not be able to debug any code if you do not have the correct .Net language
installed.
|
|
|
|
|
Thanks Stephan,
I've got it working. Now all I have to do is figure out how it works!
Regards,
John Caldwell
|
|
|
|
|
Thanks for this genius Library..
I'm using it in a great Programm to automatize Tests...
But now I found a bug I'm not able to fix...
The Code isn't able to read neated values like -10203...
Could anyone please help me fix this problem... I don't know where to find the bug..
Thanks anyway for this great snippet.. =)
|
|
|
|
|
The integer conversion is done by the sample project. The driver just returns a byte field.
Look for the function "private void ShowAs(object sender, System.EventArgs e)" and change
the code snippet
if(radWord.Checked == true)
{
if (data.Length < 2) return;
word = new int[data.Length/2];
for(int x=0;x<data.Length;x=x+2)
{
word[x/2] = data[x] * 256 + data[x+1];
}
}
into
if(radWord.Checked == true)
{
if (data.Length < 2) return;
word = new int[data.Length/2];
for(int x=0;x<data.Length;x=x+2)
{
//word[x/2] = data[x] * 256 + data[x+1];
byte[] bytes = { data[x + 1], data[x] };
word[x / 2] = BitConverter.ToInt16(bytes, 0);
}
}
Stephan
|
|
|
|
|
Is there any Modbus Class for C ?
|
|
|
|
|
C doesn't have classes. Try libmodbus.
|
|
|
|
|
When i tried to press connect button it is ok but after that when i pressed read input register button it had been given me connection lost error in Modbus tcp.
|
|
|
|
|
There is code give me error invalid address. When i try to press read input register. There is no any register value shown. My modpol utility have slave id 10 but ur code taken ur default value. Where to we give slave id value.
|
|
|
|
|
The ID hast to be changed in The HEader which is created in the DLL...
|
|
|
|
|
Hi,
I do a test for your "Modbus Tcp class demo". I got this error:Modbus says error:illegal data adress!
at first, I run two modbus tcp tools:"modbus Poll" and "modbus slave" ,they can connect well,and communication well. then i close "modbus poll",run "Modbus Tcp class demo",after I fill IP address.I click the Connect botton,then I got the illegal data adress error,a lot of same errors will show me, not stop, why? please help me! thanks!
|
|
|
|
|
Did you check your unit ID? Like the threads suggest below!
|
|
|
|
|
Thanks,I have slove this problem!
in the end of frmStart.cs,there is a funcction as follow:
private void Watchdog_Tick(object sender, System.EventArgs e)
{
MBmaster.WriteSingleRegister(0xFF, 0x1044, BitConverter.GetBytes((short) IPAddress.HostToNetworkOrder((short) 0xc1)));
}
it write a register 0x1044 to slave, but in my slave, this is no this register,so we have the error:illegal data adress
|
|
|
|
|
Hello,
if i run this application in debug mode each time i want to read some data i have following error:
Cross-thread operation not valid: Control 'grpData' accessed from a thread other than the thread it was created on, but with realese version works ok.
|
|
|
|