1

I have managed to identify both drives and serial ports in visual C# express but I still cannot access a specific device (RepRap Printer). I would like to send an array of string to it but first I need to locate it, how can I do that? I am using windows 7.

To get the drives:

using System.Linq;
using System.IO;
using System;

    class Program
    {
            static void Main(string[] args)
            {
                var drives = DriveInfo.GetDrives();
               DriveInfo[] allDrives = DriveInfo.GetDrives();
                     foreach(DriveInfo dv in drives)          
                     {              
                            Console.WriteLine("drive Name:{0}", dv.Name);      
                     }    
                    Console.ReadLine();
            }
        }

to get the serial ports:

using System;
using System.IO.Ports;

namespace SerialPortExample
{
    class SerialPortExample
    {
        public static void Main()
        {
            string[] ports = SerialPort.GetPortNames();
            Console.WriteLine("The following serial ports were found:");
            foreach (string port in ports)
            {
                Console.WriteLine(port);
            }
            Console.ReadLine();
        }
    }
}

Many thanks in advance!

Arthur Mamou-Mani
  • 2,303
  • 10
  • 43
  • 69
  • Does the device even support access to the firmware over a serial port? Your code doesn't even seem to attempt to do so. – Security Hound Aug 14 '12 at 16:01
  • @Ramhound yes right now it is connected to COM5@250000 I can see it through the software that comes with the printer. I think i need to open and close every port to check the device is there. – Arthur Mamou-Mani Aug 14 '12 at 16:07
  • 1
    If you are trying to access a printer, why are you "scanning" for "drives"? You seem to be writing a user program. The (unmentioned) OS will only allow/expose device capabilities that the device driver supports, i.e. read/write plus *ioctl()* operations. The typical method for apps to access a specific device is **by user configuration**. The pgm is told to use a type of device on a specific port in a setup dialog. This solves the problem of having 2 installed devices, and the app "finding" the "wrong" unit. If you insist at looking for serial port devices, try reading /proc/tty/serial – sawdust Aug 14 '12 at 19:28
  • @quetzalcoatl thanks! I have replaced the words. When does one uses the "firmware" to send information to a device then? – Arthur Mamou-Mani Aug 14 '12 at 20:19
  • 1
    Thanks, now it sounds much better :) In my area people tend to say either about communicating with the device, or communicating with the firmware, or with the device's operating system etc. So it is ok to use that word if you elaborate it a bit. Just the phrase "access the firmware" was misleading. Thats all! Just like "Downloading sensor readings from the firmware" sounds clearer than "Downloading data from he firmware". The latter just instantly makes me think someone wants to hack into the code/memory of the device, not that you want to actually gracefully communicate. :) – quetzalcoatl Aug 14 '12 at 20:27
  • 1
    @quetzalcoatl - The device is a peripheral & subservient to the host PC. So the host PC **downloads to** the device and **uploads from** the device. You "download from" a server because your PC is a client to the server. If you don't understand the hierarchy, just use "transfer" instead. *"Downloading ... from the firmware"* sounds like an end-user misusing jargon, which is what it is. You are accessing a *device*, not a piece of that device. – sawdust Aug 14 '12 at 20:42
  • 1
    I do not view the device I communicate with as subservient to the PC.This is a peer that maybe is an independent machine, or maybe it needs some instructions from me.The fact that we talk by this bus or that protocol does not make the device a slave.This is the architecture of usage that defines who is the master and who is the slave, assuming there is some hierarchy at all.Until some logical hierarchy of use cases is defined, in an indeterminate case, download="data incoming to ME" and upload="data outgoing from ME", because I am the manager of the transfer.http://en.wikipedia.org/wiki/Upload – quetzalcoatl Aug 14 '12 at 21:00

1 Answers1

1

I encourage you to check those two questions and answers at first:

Get the device name connected to the serial port
This one explains shortly why it is hard, but gives some clues on how to ask the Windows what does it know about the devices

Getting Serial Port Information
Here's a bunch of further code samples.

Generally, you will probably want to find the device by it's NAME that the system assigned to it - you probalby know the name and its something like "reprap#1" etc. I just guess. It may be a good idea to ask to scan all COM-device names and display it to the user so he may choose the proper one..

if you want to automaticaly detect, you can try to detect them by some lower-level details like drivername etc, but usually it is better to just leave that to the user.

Community
  • 1
  • 1
quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107