Click here to Skip to main content
15,885,201 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a function which pings ethernet ports of a device
if ping successful , green indication on c# form appears
but when i want to test another port, then i can not ping

because i need to change pc ip address to be prepared or reset current ip address
to prevent wrong ip assignment to pc
port ip is being taken with another function and lets say it is 172.3.2.1 then pc.ip is set as 172.3.2.3 to be able to ping port
but when i unplugged from that port and connect eth canle to another one having 172.3.3.1 then i want to change pc ip to an unrelated ip like 3.4.5.6 whenever i unplug cable (at exactly that moment using event handler)
then i ll wait pc ip change function to set pc ip to 172.3.3.3

What I have tried:

I have tried above things which I have told above but got failure. Please give a resolution to this.
Posted
Updated 7-Jun-16 0:29am
v2
Comments
George Jonsson 2-Jun-16 10:19am    
If you read your own question, do you think there is enough information for anyone to answer your question?
What hardware?
Where is the code you have tried?
And what is it you really want to do?
usmanali.ali843 7-Jun-16 7:49am    
Resolution to this problem what really I am missing because I am new to embedded programming so don't have enough information about this. What I have tried is when I listed my available serial com ports in a dropdown list and I picked one port then on "Set Command" button I write a command for selected com port like.
serailPort.Write("PAyacEtheLed");
And in serialPort_DataRecieved(Object sender, SerialDataReceivedEventArgs e)
I just Read and again write the bytes from select serialPort console and append console's text to my text control to show that given command's result like:
txtConsole.AppendText(serialPort.Read(dataBytes, 0, dataBytesLength));
and in response to this command which I have given above "PAyacEtheLed" router's LED blink
This is manual Com selection test, somehow passes.
But when I go to fix into code for LED tester there I have a function which iterate through all NetworkInterface IPAddressCollections,
now firstly, how could I get to know that what IP would be for my router's device which further I need to pass on to my portScan function and if IP is ping successfully then I would proceed this IP address to my LED blink function to blink LED for that IP.
But when I unplugged the device then It should get my PC IP , code should not crashed and when connect ethernet to either port of router device to my PC then It should detect the connected ethernet LED IP address and blink LED whenever I run LED tester module in my winforms.
Richard MacCutchan 7-Jun-16 7:21am    
Resolution to what? We have no idea what you mean by "but got failure".
usmanali.ali843 7-Jun-16 7:49am    
Resolution to this problem what really I am missing because I am new to embedded programming so don't have enough information about this. What I have tried is when I listed my available serial com ports in a dropdown list and I picked one port then on "Set Command" button I write a command for selected com port like.
serailPort.Write("PAyacEtheLed");
And in serialPort_DataRecieved(Object sender, SerialDataReceivedEventArgs e)
I just Read and again write the bytes from select serialPort console and append console's text to my text control to show that given command's result like:
txtConsole.AppendText(serialPort.Read(dataBytes, 0, dataBytesLength));
and in response to this command which I have given above "PAyacEtheLed" router's LED blink
This is manual Com selection test, somehow passes.
But when I go to fix into code for LED tester there I have a function which iterate through all NetworkInterface IPAddressCollections,
now firstly, how could I get to know that what IP would be for my router's device which further I need to pass on to my portScan function and if IP is ping successfully then I would proceed this IP address to my LED blink function to blink LED for that IP.
But when I unplugged the device then It should get my PC IP , code should not crashed and when connect ethernet to either port of router device to my PC then It should detect the connected ethernet LED IP address and blink LED whenever I run LED tester module in my winforms.
Richard MacCutchan 7-Jun-16 9:21am    
I think you have two issues.
1. How do you get the device to respond correctly to your messages through the serial port? This will depend largely on the device itself, and you need to consult the manufacturer's documentation to find out how to do it.

2. How to switch to a new IP address when the device is unplugged, and plugged in somewhere else? I can only assume that you will get some sort of timeout after the device is unplugged. You will then need to send a message on every available interface until you get a good response.

1 solution

You cannot ping to a specific port, ping goes only to the IP address. What you are describing is socket access to a device. So first you need to find out what messages to send to the device which will blink the LED. Then you just need to write a program to send those messages and deal with any responses. There are plenty of samples of .NET socket code that Google will find for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900