0

I am complete serial communication novice but I have been tasked to connect to an external system using serial connection so I can query the system for some data. I am doing this in Xamarin.Forms

At runtime, I need to decide whether to connect to an external system hosted in the cloud or to a system connected through serial (IP/Port) connection (hosted in house).

My initial thought to approach this is to have some kind of factory pattern determining at run time if there is an active serial connection at the port that is designated to connect to the in-house system. If so, open it and use it to talk to the in-house system; otherwise, attempt to connect to the system hosted in the cloud.

Now to my question which is probably very basic...

  • Is there a way to check if a port is being used?
  • Basically, if there is an active connection to it?
  • Or does this question even make any sense and my approach above is wrong and there is a better way or no way to do this?

From my very initial reading, it looks like there is no way to do this. All I am seeing is instruction to see if port is in use (if connection is already open).

UPDATE

To clarify, the device might be an iPad, Android tablet, or Windows UWP tablet and it is connected to a docking station through USB and docking station is connected through network cable to an external system.

cd491415
  • 823
  • 2
  • 14
  • 33
  • 2
    How would you know if the serial connection is "active"? What would that mean here? If it means that data is arriving on the serial line, the system (by the way, what targets are you using? UWP? WPF?) probably doesn't have a feature that is "stuff is coming in here, but nobody is listening." So, you could open the port and listen. Or maybe you could look at signals to see if there is a connection, but that is very dependent on the exact details of the serial port connection (like, does it bring over modem signals and/or flow control, or does it assert BREAK conditions). – bobwki Nov 05 '18 at 19:30
  • The thing is I am connecting to the system, not the other way around. So, I am the one that should create connection on that port and send and receive data. So, by "active", I guess I mean there is wired connection to that system. If so, then I can open that port (which I guess means initiate connection). Xamarin.Forms Android, iOS, UWP. Sorry if it is confusing, as I said, I am very new to this. Hope that clarifies it. – cd491415 Nov 05 '18 at 22:13
  • 1
    I'm focusing on the Serial -- OH DANG... now I see it, Serial/IP Port. So, you're not talking about a wire being attached. (I was wondering how you were going to do that, especially with the iOS device.) That is a whole 'nother shooting match. – bobwki Nov 05 '18 at 22:47
  • I think what you're looking to use is a Telnet Client. But I've never looked for one, and I don't know if it would work with iOS or Android. Seems like it could. – bobwki Nov 05 '18 at 22:51
  • I am talking about wire attached. We use special docking station for these devices. Imagine it as an iPad/Android or UWP device is docked in this docking station and the docking station itself is connected by a IP network cable or serial cable. For simplicity, let's just focus on internet IP cable. So, device is USB connected to docking station, docking station is network cable connected to the system device needs to talk to through IP, Port#. Sorry, I added update to clarify that :) Thanks – cd491415 Nov 05 '18 at 23:39
  • 1
    This is pretty far from my experience with serial ports, and it sounds like the details of the docking port will determine the solution. I'm not sure which, but to get more input to your question, you may need to edit and add tags. It sounds like you have a docking station -- with wired ethernet? with wired serial port? sounds like a mini-PC. So you may need an app that talks to a program on the docking station? – bobwki Nov 06 '18 at 17:52
  • 1
    This link might help: http://thecodewash.blogspot.com/2017/05/communicating-with-your-ios-app-over.html. I got it from https://stackoverflow.com/questions/21285841/serial-or-hid-usb-communication-in-ios-iphone-ipad – bobwki Nov 06 '18 at 17:59
  • These are known to me but thanks. No there is no need for more info really, all I am asking is "Is there a way to detect a network or serial cable is connected to device?". But after more thinking about it, I think much simple solution for me is simply to have a setting providing this information, something like if network, then here is IP/Port, else if serial, here is baud etc, or if cloud, here is your end point. That removes need to detect this connection and provides all information to then actually do serial, ip, or cloud communication. Thanks for the article, I'll definitely read :) – cd491415 Nov 07 '18 at 17:07

0 Answers0