Hello people!
Im working on a project which have no classes, just code modules, and it is constanly reciving updates for changes in firmwares of the devices i connect to manage its parameters and configuration via commands in a data stream (serial com via teraterm).
My question is if it is a good idea to make an Object call "Device" that have its commands defined in const variables with getters, setters and other kind of functions.
Here is a example code as it is "working" when sending commands :
Main Module.
This function sends the commands
maq Module.
this module is a STATE machine, where you send these commands, e.x:
This is used way many times and in different stages so im trying to make the code more readable and easier to update when the commands change or anything in the code you have to modify is easier to localize, but i dunno if it worst performance and if this is the way to do it:
Ive created a class call Device which looks, for now, like this, and its growing more:
So when i send the command it would looks like this:
And if i need to change the command just changing the constant in its class would change it anywhere in the code, BUT im confuse because usually a "getter" from an object would give you the value.
Can anyone tell me if this worth? or should i just make a Code Module for this case? or add in the function "GetIMEI" the function "comSends" so get the reply from the device and store the result this way? Hope you can give me some feedback and that is clear my confusion.
Thank you!
Im working on a project which have no classes, just code modules, and it is constanly reciving updates for changes in firmwares of the devices i connect to manage its parameters and configuration via commands in a data stream (serial com via teraterm).
My question is if it is a good idea to make an Object call "Device" that have its commands defined in const variables with getters, setters and other kind of functions.
Here is a example code as it is "working" when sending commands :
Main Module.
This function sends the commands
Main:
Public Sub comSends (s As String)
s = $"${s}${Chr(13)}"$
If portOpen Then
astream.Write(s.GetBytes("UTF8"))
End If
reply = ""
End Sub
'-----..............'
maq Module.
this module is a STATE machine, where you send these commands, e.x:
maq:
Main.comSends("/usrdata/bin/**** ***** get_firmware_version")
This is used way many times and in different stages so im trying to make the code more readable and easier to update when the commands change or anything in the code you have to modify is easier to localize, but i dunno if it worst performance and if this is the way to do it:
Ive created a class call Device which looks, for now, like this, and its growing more:
Device:
'Class Device module
Sub Class_Globals
Private fx As JFX
'--------------------------------------- Device Commands ---------------------------------------'
'------------ Getters ------------'
Private const gIMEI As String = "/usardata/bin/zbox modem get_imei" '-- get IMEI
Private const gModel As String = "zbox -v" '-- get Modelo
Private const gFirmware As String = "/usrdata/bin/zbox registry get_firmware_version" '-- get Firmware
Private const gSerialNumber As String = "/usrdata/bin/zbox registry get_device_serial_number" '-- get Serial Number
Private const gAPN As String = "zbox wuci wan.@sim[0].apn" '-- get APN
Private const gAPNUser As String = "zbox wuci wan.@sim[0].user" '-- get APN User
Private const gAPNPassword As String = "zbox wuci wan.@sim[0].password" '-- get APN Password
Private const gAtCREG As String = "zbox modem sendat AT+CREG?" '-- get AT+CREG
Private const gAtQENG As String = "zbox modem sendat 'AT+QENG='servingcell" '-- get AT+QENG
Private const gAtQCCID As String = "zbox modem sendat AT+QCCID" '-- get AT+QCCID
Private const gIpSim As String = "ifconfig rmnet_data0 | grep 'inet addr'" '-- get IP Sim
'------------ Setters ------------'
Private const sSerialNumber As String = "/usrdata/bin/zbox registry set_device_serial_number" '-- set Serial Number
Private const sUNESA As String = "/usrdata/bin/zbox wuci /usrdata/parameters registry.@device[0].serial_number_unesa=" '-- set UNESA
Private const sAPN As String = "zbox wuci wan.@sim[0].apn=" '-- set APN
Private const sAPNUser As String = "zbox wuci wan.@sim[0].user=" '-- set APN User
Private const sAPNPassword As String = "zbox wuci wan.@sim[0].password=" '-- set APN Password
Private const sBand As String = "zbox wuci wan.@sim[0].band=" '-- set Band
Private const sAuth As String = "zbox wuci wan.@sim[0].auth=" '-- set Auth
Private const sBaudRate As String = "zbox wuci wan.@sim[0].baudrate=" '-- set BaudRate
Private const sParity As Stringr = "zbox wuci wan.@sim[0].parity=" '-- set Parity
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Public Sub GetIMEI As Int
Return gIMEI
End Sub
So when i send the command it would looks like this:
maq:
Dim dev As Device
dev.Initialize
Main.comSends(dev.GetIMEI)
And if i need to change the command just changing the constant in its class would change it anywhere in the code, BUT im confuse because usually a "getter" from an object would give you the value.
Can anyone tell me if this worth? or should i just make a Code Module for this case? or add in the function "GetIMEI" the function "comSends" so get the reply from the device and store the result this way? Hope you can give me some feedback and that is clear my confusion.
Thank you!
Last edited: