vb.net - Timer which impede its own functions to run unless being in step by step -
i have issue i'm stuck since last week, , despite of advises senior developer.
i want send motorisation command motor com ports through timer.
- when step step or when add stopping point, okay! however, when let timer , program run themselves, motorisation command never happens! why? command should run far step step method does!
i calling method envoi_commande_motorisation()
without arguments. sends frames in specific format com port in order make motor move. yet seems never called when quitting debugging step-by-step. command contained timer_moto_tick(sender, e) timer_moto.tick
timer made regularly verify motor @ right azimut, knowing position demande_etat_motorisation()
.
i changed frequency of timer 1000ms 3000ms step of 500ms each time didn't changed anything...
- i added button calls
envoi_commande_motorisation()
manually , works! yet, hand , want automatize it.
here picture of crime scene:
private sub timer_moto_tick(sender object, e eventargs) handles timer_moto.tick 'asking motor position demande_etat_motorisation() 'checking if acually in automatize management of motor , not in manual way if radiobutton_manuel.checked = false 'checking if motor isn't @ right place if ((cdbl(liste_azimut.text) <> val(aff_position_azimut_source.text)) or (cdbl(liste_elevation.text) <> val(aff_position_site_source.text))) 'otherwise change motor position text , him go way lecture_port_comm_moto() liste_azimut.text = ctype(val(aff_position_azimut_source.text), string) liste_elevation.text = ctype(val(aff_position_site_source.text), string) envoi_commande_motorisation() end if envoi_commande_motorisation() end if end sub
as asked in comments gives demande_etat_motorisation
, envoi_commande_motorisation
public sub demande_etat_motorisation() dim integer dim info string if init_en_cours = true exit sub 'asking motor state 'frame in hexa : 57 00 00 00 00 00 00 00 00 00 00 1f 20 tableau_hexa(0) = &h57 = 1 10 tableau_hexa(i) = &h00 next tableau_hexa(11) = &h1f tableau_hexa(12) = &h20 'envoi de la données info = "sending frames on ports " 'port 1 ------------------------------------------------------------------------------------------------------------------------- if etat_port_4.checked = true , checkbox_moto_1.checked = true 'chosing port motorisation try select case liste_port_4.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) port_serie_3.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "error motorisation 1 : " + ex.tostring end try end if 'end if 'port 2 ---------------------------------------------------------------------------------------------------------------------- if etat_port_5.checked = true , checkbox_moto_2.checked = true 'sending command 'here chose port write in motor try 'assignation du à ouvrir select case liste_port_5.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) port_serie_3.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "error motorisation 2 : " + ex.tostring end try end if end sub public sub envoi_commande_motorisation() 'sending data on serial ports 'sending 13 chars dim integer dim cjunk, cjunk1 string dim nombre integer dim info string borneminaz = nothing bornemaxaz = nothing borneminelev = nothing bornemaxelev = nothing if init_en_cours = true exit sub if me.liste_azimut.text <> "" , me.liste_elevation.text <> "" me.zone1.text = "" 'classical command being sent tableau_hexa(0) = &h57 tableau_hexa(1) = &h30 'in degree degre tableau_hexa(5) = &h1 tableau_hexa(6) = &h30 tableau_hexa(10) = &h1 'final bits command tableau_hexa(11) = &h2f tableau_hexa(12) = &h20 'azimut calculation nombre = cint(liste_azimut.text) + 360 cjunk1 = cstr(nombre) 'numbers upper 100 cjunk = mid(cjunk1, 1, 1) tableau_hexa(2) = cbyte(&h30 + val(cjunk)) 'having decade cjunk = mid(cjunk1, 2, 1) tableau_hexa(3) = cbyte(&h30 + val(cjunk)) 'unite cjunk = mid(cjunk1, 3, 1) tableau_hexa(4) = cbyte(&h30 + val(cjunk)) 'tilt calculation nombre = cint(liste_elevation.text) + 360 cjunk1 = cstr(nombre) 'number upper 100 cjunk = mid(cjunk1, 1, 1) tableau_hexa(7) = cbyte(&h30 + val(cjunk)) 'decade recuperation cjunk = mid(cjunk1, 2, 1) tableau_hexa(8) = cbyte(&h30 + val(cjunk)) 'unite cjunk = mid(cjunk1, 3, 1) tableau_hexa(9) = cbyte(&h30 + val(cjunk)) 'affichage de la trame envoyée cjunk = "" = 0 12 cjunk = cjunk + cstr(hex(tableau_hexa(i))) + " " next envoi_azimut_elevation.text = "frame sent: " + cjunk info = "frames being sent on port : " 'port 1 'motorisation 1 -------------------------------------------------------------------------------------------------------------------- if etat_port_4.checked = true , checkbox_moto_1.checked = true 'chosing port motor 1 try select case liste_port_4.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) port_serie_3.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "erreur motorisation 1 : " + ex.tostring end try 'affichage de l'info sur l'afficheur noir 'azimut = cint(val(liste_azimut.text)) select case case 0 9 affiche_info_azimut.text = "00" + format(i, "##0") case 10 99 affiche_info_azimut.text = "0" + format(i, "##0") case else affiche_info_azimut.text = format(i, "##0") end select affiche_info_azimut.forecolor = color.green 'tilt = cint(val(liste_elevation.text)) select case case -9 -1 affiche_info_elevation.text = "-0" + format(abs(i), "##") case 0 9 affiche_info_elevation.text = "0" + format(i, "##") case else affiche_info_elevation.text = format(i, "##") end select affiche_info_elevation.forecolor = color.green end if 'port 2 ------------------------------------------------------------------------------------------------------------------------- if etat_port_5.checked = true , checkbox_moto_2.checked = true 'envoi de la commande 'choix du port choisi pour la motorisation 1 try 'assignation du à ouvrir select case liste_port_5.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) port_serie_3.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "erreur motorisation 2 : " + ex.tostring end try 'affichage de l'info sur l'afficheur noir 'azimut = cint(val(liste_azimut.text)) select case case 0 9 affiche_info_azimut.text = "00" + format(i, "##0") case 10 99 affiche_info_azimut.text = "0" + format(i, "##0") case else affiche_info_azimut.text = format(i, "##0") end select affiche_info_azimut.forecolor = color.lightgreen 'elevation = cint(val(liste_elevation.text)) select case case -9 -1 affiche_info_elevation.text = "-0" + format(abs(i), "##") case 0 9 affiche_info_elevation.text = "0" + format(i, "##") case else affiche_info_elevation.text = format(i, "##") end select affiche_info_elevation.forecolor = color.green 'demande de position demande_etat_motorisation() end if 'end if ' end if end sub
hitherto, senior developer still believes timer frequency issue.
maybe should work interruptions serial ports, how can this? told me set threshold each ports in order start reading interruption, read buffer when full.
edit:
diagnostics.debug.writeline
as advised, wrote diagnostics.debug.writeline("some specific text here")
everywhere program may have crashed. actually, after picking on lines written in terminal, noticed serialports.writeline(,,)
creates problems.
indeed whith following code , debug lines:
private sub timer_moto_tick(sender object, e eventargs) handles timer_moto.tick 'asking motor position demande_etat_motorisation() 'checking if acually in automatize management of motor , not in manual way if radiobutton_manuel.checked = false diagnostics.debug.writeline("test if @ right place") if ((cdbl(liste_azimut.text) <> val(aff_position_azimut_source.text)) or (cdbl(liste_elevation.text) <> val(aff_position_site_source.text))) lecture_port_comm_moto() liste_azimut.text = ctype(val(aff_position_azimut_source.text), string) liste_elevation.text = ctype(val(aff_position_site_source.text), string) envoi_commande_motorisation() diagnostics.debug.writeline("we have send orders camera") end if end if end sub
every debug lines being read on terminal, added in envoi_commande_motorisation()
public sub envoi_commande_motorisation() 'sending data on serial ports 'sending 13 chars dim integer dim cjunk, cjunk1 string dim nombre integer dim info string borneminaz = nothing bornemaxaz = nothing borneminelev = nothing bornemaxelev = nothing diagnostics.debug.writeline("we envoi_commande_motorisation()") if init_en_cours = true exit sub if me.liste_azimut.text <> "" , me.liste_elevation.text <> "" me.zone1.text = "" 'classical command being sent tableau_hexa(0) = &h57 tableau_hexa(1) = &h30 'transforming in degree tableau_hexa(5) = &h1 tableau_hexa(6) = &h30 'again tableau_hexa(10) = &h1 'final bits command tableau_hexa(11) = &h2f tableau_hexa(12) = &h20 'azimut calculation nombre = cint(liste_azimut.text) + 360 cjunk1 = cstr(nombre) 'number bigger 100 cjunk = mid(cjunk1, 1, 1) tableau_hexa(2) = cbyte(&h30 + val(cjunk)) 'taking decade cjunk = mid(cjunk1, 2, 1) tableau_hexa(3) = cbyte(&h30 + val(cjunk)) 'unity cjunk = mid(cjunk1, 3, 1) tableau_hexa(4) = cbyte(&h30 + val(cjunk)) 'elevation calculation nombre = cint(liste_elevation.text) + 360 cjunk1 = cstr(nombre) 'number bigger 100 cjunk = mid(cjunk1, 1, 1) tableau_hexa(7) = cbyte(&h30 + val(cjunk)) 'taking decade cjunk = mid(cjunk1, 2, 1) tableau_hexa(8) = cbyte(&h30 + val(cjunk)) 'units cjunk = mid(cjunk1, 3, 1) tableau_hexa(9) = cbyte(&h30 + val(cjunk)) displaying frame sent cjunk = "" = 0 12 cjunk = cjunk + cstr(hex(tableau_hexa(i))) + " " next envoi_azimut_elevation.text = "trame envoi : " + cjunk diagnostics.debug.writeline("we going writes") info = "sending data on ports " 'port 1 'motorisation 1 -------------------------------------------------------------------------------------------------------------------- if etat_port_4.checked = true , checkbox_moto_1.checked = true 'chosing ports try select case liste_port_4.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) 'port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) 'port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) 'port_serie_3.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm4.text diagnostics.debug.writeline("we going write in com port 4") port_serie_4.write(tableau_hexa, 0, 13) diagnostics.debug.writeline("we wrote in com port 4") timer_moto.start() 'port_serie_4.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm5.text port_serie_5.write(tableau_hexa, 0, 13) 'port_serie_5.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm6.text port_serie_6.write(tableau_hexa, 0, 13) 'port_serie_6.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "erreur motorisation 1 : " + ex.tostring end try 'displaying azimut infomations on screen 'azimut = cint(val(liste_azimut.text)) select case case 0 9 affiche_info_azimut.text = "00" + format(i, "##0") case 10 99 affiche_info_azimut.text = "0" + format(i, "##0") case else affiche_info_azimut.text = format(i, "##0") end select affiche_info_azimut.forecolor = color.green 'elevation = cint(val(liste_elevation.text)) select case case -9 -1 affiche_info_elevation.text = "-0" + format(abs(i), "##") case 0 9 affiche_info_elevation.text = "0" + format(i, "##") case else affiche_info_elevation.text = format(i, "##") end select affiche_info_elevation.forecolor = color.green end if 'port 2 ------------------------------------------------------------------------------------------------------------------------- if etat_port_5.checked = true , checkbox_moto_2.checked = true 'sending command 'chosing port try select case liste_port_5.text case zone_param_comm1.text port_serie_1.write(tableau_hexa, 0, 13) 'port_serie_1.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm2.text port_serie_2.write(tableau_hexa, 0, 13) 'port_serie_2.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm3.text port_serie_3.write(tableau_hexa, 0, 13) 'port_serie_3.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm4.text port_serie_4.write(tableau_hexa, 0, 13) 'port_serie_4.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm5.text port_serie_5.write(tableau_hexa, 0, 13) 'port_serie_5.receivedbytesthreshold = seuil_port_reception_moto case zone_param_comm6.text port_serie_6.write(tableau_hexa, 0, 13) 'port_serie_6.receivedbytesthreshold = seuil_port_reception_moto end select catch ex exception zone1.text = "erreur motorisation 2 : " + ex.tostring end try 'affichage de l'info sur l'afficheur noir 'azimut = cint(val(liste_azimut.text)) select case case 0 9 affiche_info_azimut.text = "00" + format(i, "##0") case 10 99 affiche_info_azimut.text = "0" + format(i, "##0") case else affiche_info_azimut.text = format(i, "##0") end select affiche_info_azimut.forecolor = color.lightgreen 'elevation = cint(val(liste_elevation.text)) select case case -9 -1 affiche_info_elevation.text = "-0" + format(abs(i), "##") case 0 9 affiche_info_elevation.text = "0" + format(i, "##") case else affiche_info_elevation.text = format(i, "##") end select affiche_info_elevation.forecolor = color.green 'demande de position 'demande_etat_motorisation() end if 'end if ' end if end sub
every diagnostics.debug.writeline
messages read , displayed on terminal camera doesn't move. therefore, when linked com port 4, think port_serie_4.write(tableau_hexa, 0, 13)
has serious issue, when rest of code delayed shown after. odd thing write me test if @ right place
then. if give orders move, if thought @ right place unless clicking on button calls envoi_commande_motorisation()
. .
delay
i added delay here:
case zone_param_comm4.text diagnostics.debug.writeline("we going write in com port 4") port_serie_4.write(tableau_hexa, 0, 13) system.threading.thread.sleep(500) diagnostics.debug.writeline("we wrote in com port 4")
yet, nothing change moment.
maybe should delete parts of code of question or above. feel free suggest , all bringing coping issue.
i think have tried bit @ time here. maybe need start writing simple program works, build on it.
first of all, create new project form , button. when click button, opens com port.
if works, send 1 command after opening port. command set camera @ given position.
if works, add textbox can enter wanted position. when click button, move camera position.
if works, ...
and keep building this, until find going wrong
Comments
Post a Comment