VB .net queue strange behaviour with threads - vb.net

I'm writing an vb .net form application for receiving data from commport, parsing on commport_thread and send messages to UI thread through queue.
App structure looks like this:
Private _SerialCommunicationThread As Thread
Public _DataQueue As Queue = Queue.Synchronized(New Queue())
Dim QueueLock As New Object
...
Me._SerialCommunicationThread = New Thread(AddressOf THREAD_SerialCommunication)
Me._SerialCommunicationThread.Priority = ThreadPriority.AboveNormal
Me._SerialCommunicationThread.Start()
Private Sub THREAD_SerialCommunication()
'comm port new instace, settings, start, etc
do
' copy all commport's existing bytes to rec_buffer
' parse data in rec_buffer ( my own protocol, every message has 14bytes, last is CRC sum), copy valid message (14 baytes) to buffer_work
if (CRC is OK) then
SyncLock QueueLock 'lock queue for adding message
Me._DataQueue.Enqueue(buffer_work) ' add message
'Console.WriteLine(received_messages_counter & " ID: " & buffer_work(4) & " val:" & buffer_work(5))
'buffer_work(4) is message ID byte
'buffer_work(5) is value byte
End SyncLock
end if
loop
End sub
...
'UI main thread
Private Sub Timer1_Tick ' interval=10ms
while Form1._DataQueue.Count > 0 Then
SyncLock QueueLock
buf_can = Form1._DataQueue.Dequeue()
'Console.WriteLine(received_messages_counter2 & " ID: " & buffer_work(4) & " val:" & buffer_work(5)
End SyncLock
end while
end sub
I'm sending data to COM port from microcontroler:
for(i=0,i<50;++i)
{
send_message(ID_100,i); // send message with ID=100 and data=i
send_message(ID_201,i);
send_message(ID_202,i);
};
And till parsing procedure and adding to queue console in commport thread writes exactly what is send and copy of message in buffer_work is enqueue:
1 ID: 100 val:0
2 ID: 200 val:0
3 ID: 201 val:0
4 ID: 100 val:1
5 ID: 200 val:1
6 ID: 201 val:1
...
148 ID: 100 val:49
149 ID: 200 val:49
150 ID: 201 val:49
but here comes the problem, the UI thread gives:
...
131 ID: 201 val:43
132 ID: 201 val:43
133 ID: 200 val:44
134 ID: 200 val:44
135 ID: 200 val:45
136 ID: 200 val:45
137 ID: 200 val:45
138 ID: 100 val:46
139 ID: 100 val:46
140 ID: 100 val:47
141 ID: 100 val:47
142 ID: 100 val:47
143 ID: 100 val:48
144 ID: 100 val:48
145 ID: 100 val:48
146 ID: 201 val:48
147 ID: 201 val:48
148 ID: 201 val:49
149 ID: 201 val:49
150 ID: 201 val:49
so I get exactly 150 messages but it looks like queue is enqueue in strange way...adding the same message several times, not exactly what is in buffer_work...and at the end of transmision I should have 3x49 values at 100,201 and 202 ID, but it isn't.
I thought that fifo queue behaves like enqueue A,B,C and I dequeue getting C,B,A. OK, it works but when I enqueue all messages and after that I dequeue.
When I add conditional in main UI thread:
If Form1._DataQueue.Count = 150 Then
so waiting to enqueue all 150 parsed messages in comm thread, then console prints 150 same messages received in UI thread, those all are the last sent message
...
145 ID: 201 val:49
146 ID: 201 val:49
147 ID: 201 val:49
148 ID: 201 val:49
149 ID: 201 val:49
150 ID: 201 val:49
So queue looks like to be an 1-element queue, but I need that queue will be message buffer between commport thread and UI thread, so no messaged will be lost... even if UI thread will be activ for a little longer time...
Thank you for any help and tips how to solve this problem...
Regards!

Related

Cannot open Realm database in React Native using Realm Studio

I create, open and write on a realm database using following functions:
To load the database or to create a new one I am using:
let realm = new Realm({
path: 'UserDatabase.realm',
schema: [
{
name: 'user_details',
properties: {
user_id: {type: 'int', default: 0},
user_name: 'string',
user_contact: 'string',
user_address: 'string',
},
},
],
});
Write some data:
let realmWrite = () => {
if (realm === null || realm === undefined) {
console.error('realm is:' + realm);
} else {
realm.write(() => {
var ID = 1;
realm.create('user_details', {
user_id: ID,
user_name: 'username' + ID,
user_contact: 'contact',
user_address: `asd${ID}#asd.asd`,
});
});
}
};
Apparently writing data doesn't work, so I try to open the database using Realm Studio and I get following errors:
CLASSES
Unable to open a realm at path '/Users/shinigami/Library/Developer/CoreSimulator/Devices/DEB97125-E440-4AAA-9326-7E2B8D29F158/data/Containers/Data/Application/F2B137EF-F864-454D-A622-184C95C39EEE/Documents/UserDatabase.realm': Invalid top array (ref: 1080, size: 11)
Exception backtrace:
0 .io.realm.realm-studio.SwVRf2 0x000000010dcfe581 _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 49
1 .io.realm.realm-studio.SwVRf2 0x000000010dcec970 _ZN5realm5Group18validate_top_arrayERKNS_5ArrayERKNS_9SlabAllocE + 1632
2 .io.realm.realm-studio.SwVRf2 0x000000010dcf6a20 _ZN5realm11SharedGroup7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_18SharedGroupOptionsE + 5136
3 .io.realm.realm-studio.SwVRf2 0x000000010d9f9a8c _ZN5realm11SharedGroup4openERNS_11ReplicationENS_18SharedGroupOptionsE + 236
4 .io.realm.realm-studio.SwVRf2 0x000000010d9f9473 _ZN5realm11SharedGroupC2ERNS_11ReplicationENS_18SharedGroupOptionsE + 1587
5 .io.realm.realm-studio.SwVRf2 0x000000010d964951 _ZN5realm5Realm16open_with_configERKNS0_6ConfigERNSt3__110unique_ptrINS_11ReplicationENS4_14default_deleteIS6_EEEERNS5_INS_11SharedGroupENS7_ISB_EEEERNS5_INS_5GroupENS7_ISF_EEEEPS0_ + 1145
6 .io.realm.realm-studio.SwVRf2 0x000000010d964286 _ZN5realm5RealmC2ENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEE + 278
7 .io.realm.realm-studio.SwVRf2 0x000000010d984a40 _ZZN5realm5Realm17make_shared_realmENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEEEN19make_shared_enablerC2ES1_S6_ + 84
8 .io.realm.realm-studio.SwVRf2 0x000000010d96ab44 _ZNSt3__110shared_ptrIZN5realm5Realm17make_shared_realmENS2_6ConfigENS0_INS1_5_impl16RealmCoordinatorEEEE19make_shared_enablerE11make_sharedIJS3_S6_EEES8_DpOT_ + 136
9 .io.realm.realm-studio.SwVRf2 0x000000010d97fa3c _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EERNS4_11unique_lockINS4_5mutexEEEb + 260
10 .io.realm.realm-studio.SwVRf2 0x000000010d97f8aa _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigE + 352
11 .io.realm.realm-studio.SwVRf2 0x000000010d9665fb _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 113
12 .io.realm.realm-studio.SwVRf2 0x000000010d8cb2cb _ZN5realm2js10RealmClassINS_4node5TypesEE19create_shared_realmEPN2v87IsolateENS_5Realm6ConfigEbONSt3__13mapINSA_12basic_stringIcNSA_11char_traitsIcEENSA_9allocatorIcEEEENSB_ISH_NS0_9ProtectedINS5_5LocalINS5_5ValueEEEEENSA_4lessISH_EENSF_INSA_4pairIKSH_SM_EEEEEESO_NSF_INSP_ISQ_ST_EEEEEEONSB_ISH_NSI_INSJ_INS5_8FunctionEEEEESO_NSF_INSP_ISQ_S10_EEEEEE + 127
13 .io.realm.realm-studio.SwVRf2 0x000000010d8c96c6 _ZN5realm2js10RealmClassINS_4node5TypesEE11constructorEPN2v87IsolateENS5_5LocalINS5_6ObjectEEERNS0_9ArgumentsIS3_EE + 402
14 .io.realm.realm-studio.SwVRf2 0x000000010d8c8a1b _ZN5realm4node10ObjectWrapINS_2js10RealmClassINS0_5TypesEEEE9constructERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE + 333
15 .io.realm.realm-studio.SwVRf2 0x000000010d8c9412 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 166
16 Electron Framework 0x0000000102c1e4a8 _ZN2v88internallsERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEERKNS0_18BasicBlockProfilerE + 350504
...
What's wrong?
Update
Inspecting manually the realm file I see that the file is written and filled "as expected". Please, note username and asd1#asd.asd that are literal strings from the writing function.
I solved by updating Realm Studio to its beta version.
From:
to:
This because I was trying to open a v4 Realm JS file by using with the latest version of Studio which uses Realm JS v3 internally. So I have had to download and use the beta version of Realm Studio, which uses v4.

Robotframework RIDE AutoIt control to press Stop

I am trying to use AutoIt to activate a running RobotFramework RIDE window and press the stop button. When using the AutoIt info tool I find that the Stop button is located within a toolbar. I have pasted the output from that tool here:
>>>> Window <<<<
Title: RIDE - Security
Class: wxWindowClassNR
Position: 665, 0
Size: 935, 860
Style: 0x16CF0000
ExStyle: 0x00000100
Handle: 0x0002052E
>>>> Control <<<<
Class: ToolbarWindow32
Instance: 1
ClassnameNN: ToolbarWindow321
Name:
Advanced (Class): [CLASS:ToolbarWindow32; INSTANCE:1]
ID:
Text:
Position: 304, 79
Size: 615, 28
ControlClick Coords: 45, 14
Style: 0x52001101
ExStyle: 0x00000000
Handle: 0x0003047A
>>>> Mouse <<<<
Position: 1022, 143
Cursor ID: 0
Color: 0xB6DBEE
>>>> StatusBar <<<<
1:
>>>> ToolsBar <<<<
1: 145 Start
2: 146 Stop
3: 147 Pause
4: 148 Continue
5: 149 Next
6: 150 Step over
From this output it can be seen that the Stop button has a Command ID 146.
In terms of an AutoIt script I am trying the following:
WinActivate("RIDE - Security")
ControlClick("[CLASS:wxWindowClassNR]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]", "Start")
What am I missing or doing incorrectly?
Thanks!
On ToolbarWindow32 controls you usually have to use ControlCommand with the SendCommandID option. This should work for you.
$hWinHandle = WinGetHandle("RIDE - Security")
;make sure we have focus
ControlFocus($hWinHandle, "", "[CLASS:ToolbarWindow32; INSTANCE:1]")
;uses the ControlCommand to access the stop
ControlCommand($hWinHandle, "", "[CLASS:ToolbarWindow32; INSTANCE:1]", "SendCommandID", "146")

undefined method `each' for 4294:Fixnum

I updated from Rails 3.2.3 to 3.2.8 yesterday.
this script worked up until yesterday. now i get this error:
/daily_counts.rb:32:in `<main>': undefined method `each' for 4294:Fixnum (NoMethodError)
top_posters = Load.where("created_at >= '#{today}' AND comments NOT LIKE '%Post%'").count(:all, group: "user_id", order: "COUNT(*) DESC", limit: 8)
output += "Loadmax Totals\n\s\sAll Avaliable Trucks: #{alltrucks}\n\s\sAll Avaliable Loads: #
{allloads}\n\s\sTodays Loads: #{loads}\n\s\sTodays Trucks: #{trucks}\n\nLoadmax Top Posters\n\s\sPostEverywhere: #{posteverywhere}\n\s\sPostOnce: #{postonce}\n"
posters = "\s\s"
LINE 32: Below
top_posters.each do |k,v|
company_name = Company.find(User.find(k).company_id).name unless k.nil?
poster = {
name: company_name,
posts: v
}
poster[:name] = 'MISC' if poster[:name].nil?
posters += "#{poster[:name]}: #{poster[:posts]}\n\s\s"
end
output += posters.chop.chop.chop
output += "\n\s\s"
users = "\s\s"
with the full script. it is exspose to send an email that look like this:
Total Active Loads/Trucks for Today or FutureLast 24 hours Users Logged In: 0
Loadmax Totals
All Avaliable Trucks: 409
All Avaliable Loads: 150799
Todays Loads: 78316
Todays Trucks: 169
Loadmax Top Posters
PostEverywhere: 70374
PostOnce: 2974
AMTransportServices.Inc: 2130
TNT Trucking of the Carolinas LLC: 1099
JM: 425
BOYD: 412
DANDL: 327
bijDHhgvsiKBa: 180
MTB: 177
Ultra Logistics: 131
digihaul#digihaul.com
Last Login Date 2014-06-16
Logins: 23
undefined method `each' for 4294:Fixnum (NoMethodError)
The error is due to your top_posters is 4294 which is an integer because currently it returns a count.So you can't iterate or loop through an integer.
If you want loop through top_posters it should be perhaps an array or a hash.
So you need to fix your query according to your requirements such that the top_posters is an array or a hash.

Why does the Zebra QL 220 printer shut off in the middle of my talking to it?

I've got C# CE CF code that runs on a handheld device (Motorola MC3100) which should cause the Zebra QL220 belt printer to which it is attached to print something (code appended to this post).
I turn on the QL 220 (via the big green button at its base or top, depending on your perspective) as I start my app, but the printer shuts itself off in the middle of my code executing, and so nothing is printed (I’m assuming that’s the reason nothing is printed, anyway).
If I'm right about the cause for the silence of the printer, what must I do to make its “On” button “sticky”?
I tried mashing the blue button on the QL 220, also (icon of a roller and sheet of paper being ejected from it), but all that did was spit out some of the tape/printer paper in "real time."
. . .
using (SerialPort serialPort = new SerialPort())
{
serialPort.BaudRate = 19200;
serialPort.Handshake = Handshake.XOnXOff; // Handshake AKA Flowcontrol?
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.PortName = "COM1:";
serialPort.ReadTimeout = 500;
serialPort.WriteTimeout = 500;
serialPort.StopBits = StopBits.One;
serialPort.Open();
Thread.Sleep(2500); // I don't know why this is needed, or if it really is...
// Try this first:
serialPort.WriteLine("! 0 200 200 210 1");
serialPort.WriteLine("TEXT 4 0 30 40 Bonjour la Monde"); //Hola el Mundo --- Hallo die Welt
serialPort.WriteLine("FORM");
serialPort.WriteLine("PRINT");
// or (if WriteLine does not include a carriage return and line feed):
// serialPort.Write("! 0 200 200 210 1\r\n");
// serialPort.Write("TEXT 4 0 30 40 Bonjour la Monde\r\n"); //Hola el Mundo --- Hallo die Welt
// serialPort.Write("FORM\r\n");
// serialPort.Write("PRINT\r\n");
serialPort.Close();
}
Besides appending the colon to "COM1" as ctacke revealed was necessary on another SO post, I also needed to swap the WriteLine lines for Write lines with the "\r\n" appended to each line, so that they are now:
serialPort.Write("! 0 200 200 210 1\r\n");
serialPort.Write("TEXT 4 0 30 40 Bonjour la Monde\r\n"); //Hola el Mundo --- Hallo die Welt
serialPort.Write("FORM\r\n");
serialPort.Write("PRINT\r\n");
That successfully printed out "Bonjour la Monde" although with too much wasted paper (about a mile above and below the line was printed).

Yii framework error - "failed to open stream: permission denied"

I have just started to use Yii framework on a windows 7 machine. It's giving me this annoying error and it goes away when I restart the computer.
Can anyone shed some light on what's happening and how to fix it?.. Thanks a bunch
Here is the error I get:
PHP warning
copy(C:\www\corp\assets\96296f5a\js\ckeditor\plugins\imagepaste2.3.zip): failed to open stream: Permission denied
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(131)
119
120 $folder=opendir($src);
121 while(($file=readdir($folder))!==false)
122 {
123 if($file==='.' || $file==='..')
124 continue;
125 $path=$src.DIRECTORY_SEPARATOR.$file;
126 $isFile=is_file($path);
127 if(self::validatePath($base,$file,$isFile,$fileTypes,$exclude))
128 {
129 if($isFile)
130 {
131 copy($path,$dst.DIRECTORY_SEPARATOR.$file);
132 if(isset($options['newFileMode']))
133 chmod($dst.DIRECTORY_SEPARATOR.$file,$options['newFileMode']);
134 }
135 elseif($level)
136 self::copyDirectoryRecursive($path,$dst.DIRECTORY_SEPARATOR.$file,$base.'/'.$file,$fileTypes,$exclude,$level-1,$options);
137 }
138 }
139 closedir($folder);
140 }
141
142 /**
143 * Returns the files found under the specified directory and subdirectories.
Stack Trace
#0
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(131): copy("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor\pl...", "C:\www\corp\assets\96296f5a\js\ckeditor\plugins\imagepaste2.3.zi...")
#1
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor\pl...", "C:\www\corp\assets\96296f5a\js\ckeditor\plugins", "/js/ckeditor/plugins", array(), ...)
#2
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor", "C:\www\corp\assets\96296f5a\js\ckeditor", "/js/ckeditor", array(), ...)
#3
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js", "C:\www\corp\assets\96296f5a\js", "/js", array(), ...)
#4
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(63): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets", "C:\www\corp\assets\96296f5a", "", array(), ...)
#5
+
C:\www\yii-1.1.13\framework\web\CAssetManager.php(251): CFileHelper::copyDirectory("C:\www\corp\protected\extensions\bootstrap\assets", "C:\www\corp\assets\96296f5a", array("exclude" => array(".svn", ".gitignore"), "level" => -1, "newDirMode" => 511, "newFileMode" => 438))
#6
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(458): CAssetManager->publish("C:\www\corp\protected\extensions\bootstrap\assets", false, -1, true)
453 if (isset($this->_assetsUrl))
454 return $this->_assetsUrl;
455 else
456 {
457 $assetsPath = Yii::getPathOfAlias('bootstrap.assets');
458 $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, YII_DEBUG);
459 return $this->_assetsUrl = $assetsUrl;
460 }
461 }
462
463 /**
#7
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(163): Bootstrap->getAssetsUrl()
158 * #param string $cssFile the css file name to register
159 * #param string $media the media that the CSS file should be applied to. If empty, it means all media types.
160 */
161 public function registerAssetCss($cssFile, $media = '')
162 {
163 Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . "/css/{$cssFile}", $media);
164 }
165
166 /**
167 * Registers the core JavaScript.
168 * #since 0.9.8
#8
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(124): Bootstrap->registerAssetCss("bootstrap.css")
119 /**
120 * Registers the Bootstrap CSS.
121 */
122 public function registerCoreCss()
123 {
124 $this->registerAssetCss('bootstrap' . (!YII_DEBUG ? '.min' : '') . '.css');
125 }
126
127 /**
128 * Registers the Bootstrap responsive CSS.
129 * #since 0.9.8
#9
+
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(102): Bootstrap->registerCoreCss()
#10
+
C:\www\yii-1.1.13\framework\base\CModule.php(387): Bootstrap->init()
#11
+
C:\www\yii-1.1.13\framework\base\CModule.php(523): CModule->getComponent("bootstrap")
#12
+
C:\www\yii-1.1.13\framework\base\CApplication.php(152): CModule->preloadComponents()
#13
+
C:\www\yii-1.1.13\framework\YiiBase.php(125): CApplication->__construct("C:\www\corp/protected/config/main.php")
#14
+
C:\www\yii-1.1.13\framework\YiiBase.php(98): YiiBase::createApplication("CWebApplication", "C:\www\corp/protected/config/main.php")
#15
+
C:\www\corp\index.php(13): YiiBase::createWebApplication("C:\www\corp/protected/config/main.php")
2013-02-25 11:29:18 Apache/2.2.22 (Win32) PHP/5.3.13 Yii Framework/1.1.13
The error basically says that YII is not able to copy the required assets from the extensions on to the assets directory at runtime.
The directory C:\www\corp where your YII project exists should be writable by the web server process.
I would see if there is there a firewall/anti-virus that might be blocking the web server from creating files. Try reading the web server log.