|
Post by zxrportugal on Jun 27, 2024 14:38:10 GMT -5
Hi i need some help .... writing a program based in a socket tcp ip to control lights or gates or other by cellphone or pc finally it works , of corse the most important part was´nt made by me (credits for Russel and Thorn ) , but in liberty basic i´m having errors that doesn´t happen in LBB. the program works good in server mode in Lan or Wan with my cell phone using UDP TCP SERVER App (Android) but i´m losing a byte so the solution for now its to put a one more letter in the message sent by the app . the speed is very fast in wan mode !!!! ( using the cell phone network ) and we can send messages from pc to ! the design is to add a program module that adds the control to com ports and interfacing with a plc siemens s200 that i have to control the outputs of plc .... but now i need that it works not in lBB but in normal liberty basic most time the program crash in lberty basic , but in LBB it works very well .... AS you now i´m a novice in programing but i´m a professional electromecanic .... someone interested to help and join ? we need the WM liberty Dll file to work !!! Regards from Portugal consola 4 botoes recebendo tcp 0.4.3 e envi....bas (21.84 KB)
|
|
|
Post by Rod on Jun 28, 2024 3:43:59 GMT -5
Well the first thing I notice is that you have a mix of [branch] label code and Subs and Functions. That's always been a problem since there are events that will fire and you may be in a Sub or Function that has no knowledge of your [branch] label. If you use Subs you are much safer writing all Sub code, so the button handlers need to be Subs. If you are losing a byte you probably need to remember that strings are terminated with a hidden chr$(0) But.
What errors are you getting and can we see the error.log
|
|
|
Post by Brandon Parker on Jun 29, 2024 10:29:04 GMT -5
If you are losing a single byte, the issue is most likely a Struct size issue for an element that is defined as "Char[x]" in the Struct definition. Liberty BASIC always appends a chr$(0) as the last character in a Struct element defined as "Char[x]" even if that means truncating characters. So if you require 8 characters in your Struct, try making it 9 and see if the issue resolves itself.
Here is a short bit of code that shows the truncation in the first section.
Struct sockaddr, sinzero As Char[12] sockaddr.sinzero.struct = "Hello World!"
Print sockaddr.sinzero.struct Print
Struct newsockaddr, sinzero As Char[13] newsockaddr.sinzero.struct = "Hello World!"
Print newsockaddr.sinzero.struct
There could be more issues, but missing the last byte and knowing this issue to out there, makes me want to start there.
{:0)
Brandon Parker
|
|
|
Post by zxrportugal on Jun 30, 2024 8:47:19 GMT -5
Well here I leave the log file all it takes is a crash in liberty basic and I won't be able to start again with the program " invalid argument - error ", another small bug verified when I increase the size of the image , the graphic boxes turn white , Flush command missing ? In LBB it goes well, although I realize in part that it's not the same..... The great thing here is that the socket is very similar to what is written in other languages, so I presented the complete original program for everyone to see .....
some logs. Error log timestamp Sunday 30/06/24 00:09:12
Runtime error: index: 3013 is outside of collection bounds
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'index: 3013 is outsi...'> BasicProgram(Object)>>error: <'index: 3013 is outsi...'> BasicProgram>>terminateRun: <anError> [] in BasicProgram>>errorHandlerBlock ExceptionHandler>>evaluateResponseBlock: <aBlockClosure> for: <anError> [] in ExceptionHandler>>handle: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>handle: <anError> ExceptionHandler>>findHandler: <anError> Error(Exception)>>activateHandler: <anExceptionHandler> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'index: 3013 is outsi...'> OrderedCollection(Object)>>error: <'index: 3013 is outsi...'> OrderedCollection(IndexedCollection)>>errorInBounds: <3013> OrderedCollection>>at: <3013> put: <'loop estado de saíd...'> StringModel>>replaceLinesIn: <aTextSelection> with: <'loop estado de saíd...'> StringModel>>replace: <aTextSelection> withText: <'00:09:00'> BasicTextPane(TextPane)>>replaceWithText: <'00:09:00'> BasicTextPane>>pasteString: <'00:09:00'> BasicTextPane>>nextPutAll: <'00:09:00'> BasicTextWindow(TextWindow)>>nextPutAll: <'00:09:00'> BasicProgram>>nextPutAll: <'00:09:00'> [] in PrintCommand>>textCr: BasicDoubleParameterContextHolder>>value [] in BasicProgram>>begin ExceptionHandler>>evaluateProtectedBlock: <aBlockClosure> [] in ExceptionHandler>>activateDuring: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>activateDuring: <aBlockClosure> ExceptionHandler class>>handle: <anError class> with: <aBlockClosure> during: <aBlockClosure> BlockClosure>>on: <anError class> do: <aBlockClosure> BasicProgram>>begin BasicProgram>>gotoAndIfStoppedBegin: <'[button7Click]'> BasicProgram>>handlerName: <'[button7Click]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[button7Click]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[button7Click]'> callParameters: <anOrderedCollection> LibButton>>click BasicWindow>>click: <aLibButton> LibButton(Button)>>click: <aLibButton> Message>>perform Message>>evaluate LibButton(Object)>>triggerEvent: <#clicked> LibButton(Button)>>triggerClickedEvent
right now i can send messages to lan or wan but can´t receive ..... thanks for help !!!!
|
|