|
|
Ai có thể chuyển mã nguồn modbus tcpc lass (C#) sang Vb.net giúp không ạ!? 
|
|
|
|
|
Hello Stephen:
I am using your Modbus library for my project and I have some questions to discuss:
Basically, my project connects to multiple TCP devices. It has to read multiple hodling registers with different data legth from each device. Readmultiple register function cannot be used. Here is what I am doing with a single device. I am calling a thread and thread function is as shown below:
Master MBmaster;
try
{
MBmaster = new Master(IPAddr.Text, 502);
MBmaster.OnResponseData+= new Master.ResponseData(MBmaster_OnResponseData);
MBmaster.ReadHoldingRegister(3, 2, 15, 1);
MBmaster.ReadHoldingRegister(3, 2, 11,2);
if (word != null) { SetText(Convert.ToString(word[word.Length-1]),1); }
MBmaster.ReadHoldingRegister(3, 2, 13, 2);
if (word != null) { SetText(Convert.ToString(word[word.Length - 1]), 2); }
MBmaster.ReadHoldingRegister(3, 2, 30, 2);
if (word != null) { SetText(Convert.ToString(word[word.Length - 1]), 3); }
MBmaster.ReadHoldingRegister(3, 2, 32, 2);
if (word != null) { SetText(Convert.ToString(word[word.Length - 1]), 4); }
}
catch (SystemException error)
{
MessageBox.Show(error.Message);
}
My questions:
- I want to pass a local int value from my thread to the event as a refernce.
So in the event it gets updated. Is there any way it can be done?
Please let me know. Happy to discuss in detail if required.
Thank you very much in advance,
Shwetha
|
|
|
|
|
Hi,
Do you have this protocol for C++ or C,I want to use it in QT Designer
|
|
|
|
|
Hi,
I am sorry but I think you would have to write a wrapper class to do that. Here is some documentation
[^]
but I am not sure if that works with modbus driver.
Stephan
|
|
|
|
|
First, I would like to Thank you for putting this project up on this site. Everything you noted is working great. Just curious, if you are connected to a Modbus TCP/IP gateway, but a modbus device doesn't respond at all, is there away for an exception to be thrown? Just wondering.
Thanks,
Member 12709792
|
|
|
|
|
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
|
|
|
|