# Port(p) hash function
Valid for use with hash commands: HMI, Open_Serial
Sets the serial port address to be used for communications.
The default port is mapped to RAM address 251, and is identical to the programming serial port. Until May 2013 that was the only port possible. In June 2013 we started introducing the ability to support more ports, both real (physical) and virtual.
If you do not want to use any port other than 251, you do not need to use the Port hash function.
If you do want to use a port other than 251 (this will be documented for the particular board you are using), you need to use the Port
hash function. Port
is generally needed in two places:
- In the Open_Serial hash command that sets up the serial port (not required if you are using a virtual port)
- In, and only in, the very first
#HMI
hash command in your program, and as the first hash function within that command. This must be the first HMI function that gets processed by the translator ("at compile time"), taking into account the order of multiple files if you are using Builder.
Reminder: A hash command is the first key word after a #. A hash function appears after the command keyword, and supplies various parameters. A given hash function is legal only with one or more specific hash commands.
The following sample code is from the top of a program (the initialisation sequence) that would be using SimpleHMI on an Android device via a third party JY-MCU Bluetooth module connected to the serial port on an EC1 board.
EC1_Serial EQU 252 ;Serial port on EC1 "EasyOne" # Open_Serial Port(EC1_Serial) User(9600,8,N) ;Initialise the serial port # HMI Port(EC1_Serial) ConnectEvent(HMI_Connect) ;Where to GoSub when the SimpleHMI connects GoSub HomeScreen ;Show the home screen LaunchTask ..... etc ..... RunTasksForever
Note the use of a symbolic name (EC1_Serial
) for the port. This makes it easier to switch to a different port, for example switching between a Bluetooth connected Android device on port 252 and the SimpleHMI client built into SPLat/PC on port 251. However, in boards that do not support multiple serial ports this may cause problems, so should not be done. You can just use the literal port number, e.g Port(251)
- 251 being the only port in such boards - or simply not use Port()
at all.