stephan1827 / modbustcp-dotnet Goto Github PK
View Code? Open in Web Editor NEWVisual Studio modbusTCP class
License: MIT License
Visual Studio modbusTCP class
License: MIT License
Good morning,
Am I not understanding the code the right way, or is the transaction identifier in the frame the master sends, the function code, and not a unique number that identifies the transaction?
Sorry for the trouble, and thank you very much for your help
Dear stephan
I am from Taiwan. Thanks for this source code, It is very helpful for me to study C#.
By the way, I have some question after I use Threading.Task . Is it possible to do Parallel.For to connect multi-IP to get register values.? I do not know how to design local variable. I hope you can give some suggestion.
Here is my code
public partial class Form1 : Form
{
bool Trigflag = false;
int[] stor = new int[1];
private void timer1_Tick(object sender, EventArgs e)
{
Parallel.For(0, IP.Length, (j, state) =>
{ MBmaster = new Master(IP[j], 502, true);
MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException);
MBmaster.ReadHoldingRegister(3, 0, 0, 100);
while(!TrigFlag)
{
Console.Writeline("waiting for response");
Thread.Sleep(50);
}
TrigFlag = false;
for (int ll = 0; ll < stor.Length; ll++)
{ Console.Writeline(stor[ll]);}
});
}
private void MBmaster_OnResponseData(ushort ID, byte unit, byte function, byte[] values)
{
// ------------------------------------------------------------------
// Seperate calling threads
if (this.InvokeRequired)
{
this.BeginInvoke(new Master.ResponseData(MBmaster_OnResponseData), new object[] { ID, unit, function, values });
data = values;
ShowAs(null, null);
Trigflag = true;
return;
}
}
private void ShowAs(object sender, System.EventArgs e)
{
bool[] bits = new bool[1];
int[] word = new int[1];
if (data.Length < 2) return;
int length = data.Length / 2 + Convert.ToInt16(data.Length % 2 > 0);
word = new int[length];
for (int x = 0; x < length; x += 1)
{
word[x] = data[x * 2] * 256 + data[x * 2 + 1];
}
}
stor =word;
}
This code can be use in for loop. But in the multi-Thread Parallel.For function, it exist local var and global var problem.
I do not know how to fix it, Can you give some suggestion?
Hi,
Could you please tell me what license applies for https://github.com/stephan1827/modbusTCP-DotNET/tree/3.3.
Thank you
On the test app, if you click "Bits" followed by "Write Single Register" the app crashes. It is expecting a 2-byte array and the routine is only supplying a 1-byte array.
How can I make it read floating values?
Hello,
I was wondering if you tried to work with FC16 (async). I get no response from the MB device, no matter how i read it, even if i isolate it in a separate project.
I'm opening the connection, I'm sending fc16, but getting no response. The reading functions work, this is the only issue I've encountered, and I'll look into it further. I was just wondering if it's a known bug.
I'm communicating with the plc using the library you shared. I have to constantly read and write data from plc. But when the connection is open for a long time, it breaks.
Readme says the following description;
Remember that a lot of Modbus clients use a watchdog telegram to make sure the master is still active. If you don’t call this watchdog within a specified time, the slave will close the connection. This feature is used to avoid unused open ports when the connection is interrupted.
How can I resolve the disconnection?
Thank you for your sharing and support.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.