SERIN2 Command Syntax


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default SERIN2 Command Syntax

    Would this command work?

    Code:
    serin2 Rx,16780,[WAIT("!"),BytesIn\BytesIn[0]\\"~"]
    I want to be able to send a variable length packet between two MCU. I'm not sure if I can reference a byte coming in as the packet length or not.
    Last edited by CocaColaKid; - 23rd November 2005 at 16:31.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Cool, what a great question!!   Unfortunately, the answer is no. For a couple of reasons.

    First, you forgot the "STR"

    Second, the STR portion of the SERIN2 command, grabs the number of bytes to receive at the start of execution, and doesn't check to see if it's changed later on.

    If you look at the .ASM file generated for this line it looks something like this... (comments added by me)
    Code:
    ; SERIN2~1.BAS	00018	serin2 Rx,16780,[WAIT("!"),str BytesIn\BytesIn[0]\"~"]
    	SERIN2DPIN?T	_Rx             // PIN to use _Rx
    	SERIN2MODE?C	0418Ch          //  Mode 16780
    
    	LABEL?L	L00001	
    	SERIN2WAIT?CL	021h, L00001    // wait for "!"
    
    	SERIN2COUNT?B	_BytesIn        // Number of bytes to receive
    	SERIN2CHAR?C	07Eh            // terminating character
    	SERIN2STRC?B	_BytesIn        // Get the String
    However, I think this might work.

    SERIN2 Rx,16780,[WAIT("!"),BytesIn[0], STR BytesIn[1]\BytesIn[0]\"~"]

    Code:
    ; SERIN2~1.BAS	00020	serin2 Rx,16780,[WAIT("!"),BytesIn[0], str BytesIn[1]\BytesIn[0]\"~"]
    	SERIN2DPIN?T	_Rx             // PIN to use _Rx
    	SERIN2MODE?C	0418Ch          // Mode 16780
    
    	LABEL?L	L00002	
    	SERIN2WAIT?CL	021h, L00002    // wait for "!"
    
    	SERIN2?B	_BytesIn        // get number of bytes in packet
    
    	SERIN2COUNT?B	_BytesIn        // STR byte count
    	SERIN2CHAR?C	07Eh            // terminating character
    	SERIN2STRC?B	_BytesIn + 00001h  // Get the STR

    <br>
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    I had the STR in original but I must of changed it and forgot to put it back. Basically you get the packet length in the first byte then tell it to receive a string starting at array address 1 instead of 0. However would the \Byte[0] on the end not read \(Byte[0]-1) since the first byte was already received?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    would the \Byte[0] on the end not read \(Byte[0]-1) since the first byte was already received?
    I guess that depends on what the first number contains.
    If the number includes the "Length Byte" then yes, it would be Byte[0]-1.

    But then, it might indicate the "whole" packet length, including the "!", then it would be Byte[0]-2.
    <br>
    DT

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 20:10
  3. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 02:38
  4. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  5. SEROUT2 and SERIN2 commands
    By bangunprayogi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th August 2005, 09:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts