in reply to Serial camera - Issues connecting

I don't see anything glaringly wrong with the serial port handling, It is difficult to be sure without seeing the tpj4.cfg file though. Have you tried terminating the commands with a \n instead of \r? Or without the \r? Sometimes things expect unusual command terminators.

As an aside:

$FrameNum = substr($ResultUnpacked, 6,2); $FrameHex = '0x' . $FrameNum; $FrameNum = eval $FrameHex;

could be more succinctly written as:

$FrameNum = hex substr($ResultUnpacked, 6,2);

Also, you should probably drop the '0x.' from your $Ack pack $FrameNum field. It doesn't do anything. It is just being silently ignored.

my $Ack = pack( 'C*', 0xaa, 0x0e, 0x0d, $FrameNum, 0x00, 0x00);

instead of

my $Ack = pack( 'C*', 0xaa, 0x0e, 0x0d, 0x.$FrameNum, 0x00, 0x00);

UPDATE: Do you need to send more SYNC commands to the camera? The docs state that it requires 25 to 60 SYNC commands before it will issue an ACK.

Replies are listed 'Best First'.
Re^2: Serial camera - Issues connecting
by SquareJ (Novice) on Feb 15, 2012 at 00:52 UTC

    Thanks Thunder, will streamline the code as you suggested. On the syncs, i repeat all the commands until i get the expected success code as passed in as the second parameter sent to sub SendCommand. I need to limit the number of retries but figure that will be a later addition, also will be adding something to power cycle the camera if i get to 60 with no success. Here is the config file, wondering if the handshake part is failing, i have tried RTS, XOFF, DTR and none they dont seem to make a difference. I have no experience with this level of serial so thanks for taking a look.

    Win32::SerialPort_Configuration_File -- DO NOT EDIT -- \\.\COM4 CFG_1,none eol,10 clear,-@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@- RCONST,1000 istrip,0 CFG_2,none XOFFCHAR,19 PARITY_EN,0 WCONST,200 intr,3 U_MSG,1 STOP,1 XONLIM,2048 erase,8 XONCHAR,17 BINARY,1 RTOT,0 echonl,0 XOFFLIM,512 icrnl,0 inlcr,0 READBUF,4096 igncr,0 EOFCHAR,0 WRITEBUF,0 RINT,4294967295 ocrnl,0 bsdel,  opost,0 echoke,1 PARITY,none HNAME,localhost echoctl,0 CFG_3,none EVTCHAR,0 icanon,0 isig,0 HADDR,0 E_MSG,1 DATA,8 DVTYPE,none echo,0 quit,4 s_eof,26 s_kill,21 ERRCHAR,0 onlcr,1 ALIAS,COM4 HSHAKE,none DATYPE,raw echok,1 echoe,1 BAUD,57600 WTOT,10

      OK, after pulling my hair out on this i tried simply sending 30 sync commands in a row, one pack command with 30 iterations all at once then started the normal sync and other commands. This worked! Purely a guess that it took many characters for the serial port and cam to sync baud?? but its working. The confusing part was that after the first couple of syncs i would get an ACK but then subsequent commands, like set picture size, would never get a response.

      Thunder, the shortcut to find the frame num with hex worked great, removing the leading 0x's did not, complained at runtime. Appreciate you looking at this for me.