Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

RS-232 via Camera Link

Solved!
Go to solution

I pieced together some VC++ code to open an RS-232 connection via camera link and send/receive commands. The code compiles and runs, but I am not getting any response from the camera. The command I am sending is directly from teh vendor, so for the moment I am assuming it is correct. Is the code below correct? I would be very appreciative if someone could look over the code below and let me know if I a missed anything. Thanks.

 

I verified that the interface file contains the reference to the camera that I am using and that the camera file is setup to support serial communication at 56 kbaud.

 


  void sendCommand(void) {
    int error ;
    Int32 nSerial, size ;
    char response[9] ;
    char name[64] ;
    char buffer[] = { 0x49, 0x73, 0x65, 0x03, 0x3F, 0x04, 0x00, 0x28, 0x0D } ;  // Sample camera command from vendor
    char text[32] ;

    unsigned int    bitsPerPixel;
    DWORD            dwThreadId;
    
    // Create the event that needs to be signaled when we
    // wish to stop the acquisition.
    HStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!HStopEvent) return ;

    // Create the thread that is responsible for shutting
    // down the acquisition
    HStopThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) StopThread, (LPDWORD) &HStopEvent, 0, &dwThreadId);
    if (!HStopThread) return ;

    // Get the interface name
    GetWindowText(HIntfName, name, 64);    // HIntfName is HWND, or handle to interface = img0, which is correct
    

// Get the interface name
    errChk(imgInterfaceOpen(name, &Iid)) ;
    errChk(imgSessionOpen(Iid, &Sid)) ;
    
    errChk(imgGetAttribute (Sid, IMG_ATTR_GETSERIAL, &nSerial)) ;
    sprintf(text, "%dddd", nSerial);  // Get the index of the serial connection and display in a text box
    SetWindowText (HSerialOut, text);  // HSerialOut is the handle to a text box

    size=sizeof(buffer)/sizeof(char) ;  // # chars in command buffer (9)
    imgSessionSerialWrite(Sid, buffer, &size, 2000) ;  // 2 sec timeout for write (should be more than enough)
    imgSessionSerialRead(Sid, response, &size, 2000) ;  // Same for read

    sprintf(text, "%s", response);
    SetWindowText (HSerialOut, response);  // Do not get any printout and no error messages


Error :
    if(error<0) {
      DisplayIMAQError(error);
      PostMessage(ImaqSmplHwnd, WM_COMMAND, PB_STOP, 0);
    }

       return ;
  }

0 Kudos
Message 1 of 3
(5,965 Views)

Hi cdl3,

 

From looking over the code I do not see anything that pops out being wrong. What is the make and model of the camera you are using? After running this code what is in the buffer and response variables?

 

Tim O

Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(5,948 Views)
Solution
Accepted by topic author cdl3

Tim:

 

     The code is working; the issue is that both teh serial write and read calls return 0, which I was interpreting as the # of bytes sent and received, respectively. It looks like 0 simply means that the call worked, which I determined was the case by looking at the response. Thanks for your help.

 

  Charles

0 Kudos
Message 3 of 3
(5,945 Views)