My project has both USB and RS485 com ports. I would like to switch between active com ports by using a hardware dip switch. This would save a lot of code and time.
OK, so we know this will not work. Melanie explained why in this post http://www.picbasic.co.uk/forum/showthread.php?t=11801 but stopped short of a solution to the problem, if there is one. I’ve found several posts on this subject, none of which find solutions.Code:DS1 VAR PortA.1 ;dip switch TX_USB VAR PortC.6 TX_RS485 VAR PortC.5 ComVar VAR BYTE If DS1=1 then ComVar=TX_USB Else ComVar=TX_RS485 EndIF Serout1 ComVar, 84 [“Transmitting “]
So how do I set a Port Variable within a Serout statement to switch between two ports?
This compiles but it doesn’t work either, Is it for the same reasons the first example failed? There must be some way to solve this problem ??? There must be a different approach that I just haven’t found. Comments please.Code:If DS1=1 then ComVar=6 Else ComVar=5 EndIF If ComVar=7 then Serout2 PortC.0[ComVar], 84, [“ Com is USB”] Else Serout2 PortC.0[ComVar], 84, [“ Com is RS485”] EndIF




Bookmarks