|
There is an exception that will be triggered when the master does not respond at all. It may just take up to 30 seconds to fire.
try
{
MBmaster = new Master(txtIP.Text, 502);
MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException);
grpExchange.Visible = true;
grpData.Visible = true;
}
catch(SystemException error)
{
MessageBox.Show(error.Message);
}
|
|
|
|
|
Thanks! I believe I got it working now. Appreciate the response.
|
|
|
|
|
Hi,
I'm new to Modbus, and am trying this project. However, on hitting the "Connect" button in the demo app, I'm getting the following error:
"No connection could be made because the target machine actively refused it."
I'm running VS2017 with admin privileges.
Thanks.
|
|
|
|
|
You might have already figured this out, but just in case you didn't. You need to be either running a modbus TCP/IP simulator or actually connected to a modbus gateway device for you to actually connect.
Regards,
|
|
|
|
|
Hi,
I have the following problem.
I have a application which can send input data (strings, ints and bools) to a machine, using OPCdotNETlib. Now I also wanted to add a new machine so that my program can send its values using Modbus TCP.
This example works perfect.
Then I changed some things in this example:
The radiobutton always set to word.
Unit always 1
Start address always 0
Size always 16
Only using "Read Holding Register" and "Write Multiple Register"
Connect button is now not important anymore, since it will check for connection when you click "Read Holding Register"
It still works perfect.
I tried to add this same code and principle to my program, using the already excisting Modbus class, but instead of sending the values in the TexBoxes, it has to send values from the SQL database in my program. Here is where it goes wrong.
If you look in the sample program to GetData, you can see the way the values are send. In my case, I edited the code to:
public byte[] GetData(int num, int ARecipe)
{
bool[] bits = new bool[num];
byte[] data = new Byte[num];
int[] word = new int[num];
if (!FParams.Any())
{
Console.WriteLine("");
return null;
}
foreach (DParamvalue param in FModel.DParamvalues.AsQueryable().Where(p => p.recipeid == ARecipe))
{
int x = Convert.ToInt16(param.value);
if ((x <= data.GetUpperBound(0)) && (param.value != ""))
{
try { word[x] = Convert.ToInt16(param.value); }
catch (SystemException)
{
word[x] = Convert.ToUInt16(param.value);
};
}
else break;
}
data = new Byte[num * 2];
for (int x = 0; x < num; x++)
{
byte[] dat = BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder((short)word[x]));
data[x * 2] = dat[0];
data[x * 2 + 1] = dat[1];
}
return data;
}
Where ARecipe = frecipeid (in the sql table). So for each ARecipe, it has to send the values of that specific frecipeid (which also can be 2, 3, 4 etc.).
Now the problem: my program does not send 5, 8 and 9 for example, but 0, 0 and 0. So the program is connected correctly and it can send data, but not the data I want it to send from the database.
How can I make sure it sends the data from the database?
I hope I explained it well enough and that someone can help me.
Ganesh
|
|
|
|
|
How to end the connection using modbus using code?
I want to click a button, where the program connects, sends the values and then ends the connection.
|
|
|
|
|
Hi, thank you for your sharing. When we use ReadHoldingRegister (Async) no problem we can get data but
when we use ReadHoldingRegister as Sync with (ref byte[] parameter), we get "Connection is lost!" exception. We look source, take exception line is --int result = tcpSynCl.Receive(tcpSynClBuffer, 0, tcpSynClBuffer.Length, SocketFlags.None)"-- Could you help us about this? Thanks
modified 1-Aug-17 9:10am.
|
|
|
|
|
I tried to run this as a class file. It keeps throwing error as 'No main method suitable for entry point. Please help
|
|
|
|
|
Hi
I have a delta plc DVP-12se.I'm trying to read the registes and coils using the application but just need some clarity on how the values need to be entered (are they in hex format) Can u plz provide me with the values that I would need to enter if I want to read input X0 and coil Y0
Thank u
|
|
|
|
|
HI,sir
who method
ushort ID = 3;
byte unit = 2;
ushort StartAddress = 0;
byte Length = 1;
How to remove??=MBmaster.ReadHoldingRegister(3, 2, 0, 1);
that all
thank you
|
|
|
|
|
I am not very good at programming so I am trying to reading of discreet inputs and riwting in the coil but always disply this msg: moddbus says errror ; illegal data adress!.
|
|
|
|
|
mate, unless you provide more info, for instance, the type of PLC/Modbus device you're reading from, and what settings you've tried, I doubt people can help you. On one particular device Ive used, for some bizarre reason, I have to offset the addresses by +1.
|
|
|
|
|
i have PLC rackwell iwant read and riwte by modbus ,the first one i can read the input discrte iputs and coil ,but i have problem for writing in coils single and multiple .
|
|
|
|
|
Greetings,
Having trouble connecting with both the sample app and my application. Connects fine to Mod_RSsim modbus simulator. Won't connect to a Delta-Tau brick controller.
Wireshark trace is here:
https://www.dropbox.com/sh/2kgv1t72evq7pk7/AAD8cZMDS2cD7COlEmeBYx0Wa?dl=0
It shows two connections, and then the second connection gets an RST (three times - TCP Suprious Retransmission)
My app just times out on the connect to the brick controller.
Looking for any ideas on what to check or try. Thanks all in advance.
|
|
|
|
|
Solved: In the case of the Delta Tau brick controller. When it is in server mode it will only allow one socket connection. The ModbusTCP library connects twice (sync and async). I commented out the sync connect code and the modbus app seems to happily connect to the brick controller now.
|
|
|
|
|
Hello.
tell me how to register values with a comma? registers in the slave values with a comma (eg 21,6) and when getting the value of artists get 21! Thank you
private void ShowAs(object sender, System.EventArgs e)
{
double[] iword = new double[reg_count];
string[] word = new string[reg_count];
if (data.Length < 2) return;
iword = new double[data.Length / 2];
word = new string[data.Length / 2];
for (int x = 0; x < data.Length; x = x + 2)
{
iword[x / 2] = data[x] * 256 + data[x + 1];
word[x / 2] = iword[x / 2].ToString();
}
for (int i = 0; i < word.Length; i++)
{
res[i] = word[i].ToString();
}
}
|
|
|
|
|
Hey, this is wonderful application. i used it in connection between Delta PLC and Ethernet. But i am facing a problem , After few time this lost it's Connection Automatically and error occurs "Connection Lost". And in my Application i need the connection continuously.Even 1 sec lost connection is also not allowed. so can u please let me know how to solve this problem?
|
|
|
|
|
I would need Wireshark traces to see why it is disconnecting. Also make sure that you don't poll datat too fast. Maybe the slave is not able to keep up with the requests.
Stephan
|
|
|
|
|
Hi megha_p,
I seem to be getting the same Connection lost Problem.
Did you get this solved and figure out the cause?
Thanks,
Rob
|
|
|
|
|
Very nice job, thanks a lot.
|
|
|
|
|
I want to poll specific register suppose only 40001.Using onresponse data it polls all the registers starting from start address to number to registers to poll.I want to poll only specific address mention in my Textbox.
|
|
|
|
|
Register 40001 means that this is a holding register with address 1 (or 0 Modbus on not quite clear on that). So what you have to do is read holding register from address 1 with length 1.
Stephan
|
|
|
|
|
Though the code is a bit too hard-coded for my taste, this application gets the job done. Thanks! You saved me so much time at work.
|
|
|
|
|
Nice job developing the Modbus library but, the downloaded file does not contain the .doc file suggested. "The class directory contains a help file (ModbusClassTCP\doc) with detailed information for every function." I do however find a .chm file but I get no data, just titles of the data I would like to view. Is there a way I could get the documentation on the library for Modbus? This would help speed development time. Thanks for your help.
AutomationBrent
|
|
|
|
|
If you dont see any content in the CHM file, do a right click on the file and select properties. Then click on the Unblock button in the top right corner. Now the content should show up fine.
Stephan
|
|
|
|