I have taken a look at the code to send data using Write Multiple Registers, but I want to send data using the values in textboxes instead of the listbox.
Your code:
try{if(!modbusClient.Connected){modbusClient.IPAddress=txtIpAddressInput.Text;modbusClient.Port=int.Parse(txtPortInput.Text);modbusClient.Connect();}int[]registersToSend=newint[lsbWriteToServer.Items.Count];for(inti=0;i<lsbWriteToServer.Items.Count;i++){registersToSend[i]=int.Parse(lsbWriteToServer.Items[i].ToString());}modbusClient.WriteMultipleRegisters(int.Parse(txtStartingAddressOutput.Text)-1,registersToSend);}catch(Exceptionexc){MessageBox.Show(exc.Message,"Exception writing values to Server",MessageBoxButtons.OK,MessageBoxIcon.Error);}
Hi,
I have taken a look at the code to send data using Write Multiple Registers, but I want to send data using the values in textboxes instead of the listbox.
Your code:
My code:
However, I get the error: 'Input string was not in the correct format.'
Do you have any ideas to solve this?
Ganesh
Hi Ganesh,
it seems to be a problem while parsing the String. Please make sure that spParamvalues.Children[i].ToString() are only numbers.
Stefan
Hi Stefan,
They are only numbers, but I still get the error. Even when I read the machine and then send the exact same values back, I get the error.
Hi Ganesh,
you should see were the Exception is thrown, and I think it is thrown in line
registersToSend[i] = int.Parse(spParamvalues.Children[i].ToString());
So I think it is definitely an parser Exception.
I don't kno what is spParamvalues.Children[i]? If these are textboxes is it possible that you have to write
registersToSend[i] = int.Parse(spParamvalues.Children[i].Text); ?? Try to set a breakpoint and findout what string you are trying to parse.
Stefan
Rewriting the registersToSend[i] helped, thanks!