Adobe Air and Serial Port Communication with Serproxy/Thinkerproxy - air

I'm using serproxy / thinkerproxy for serial communication in a small Air app.
I have two hardware devices to test it. One is a barcode scanner, it works perfectly.
The other is a custom board. It's kind of working also. The problem is that the characters are unreadable. I think it's a problem of charset (not sure) so I tried something like this in the function that handles the ProgressEvent.SOCKET_DATA event:
var cs:Array = new Array( 'ISO-8859-1',
'ISO-8859-2',
'ISO-8859-3',
'ISO-8859-4',
'ISO-8859-5',
'ISO-8859-6',
'ISO-8859-7',
'ISO-8859-8',
'ISO-8859-9',
'ISO-8859-10',
'ISO-8859-11',
'ISO-8859-12',
'ISO-8859-13',
'ISO-8859-14',
'ISO-8859-15',
'ISO-8859-16',
'ISO-8859-17',
'ISO-8859-18',
'ISO-8859-19',
'ISO-8859-20',
'ASMO-708',
'DOS-720',
'x-mac-arabic',
'windows-1256',
'ibm775',
'windows-1257',
'ibm852',
'x-mac-ce',
'windows-1250',
'gb18030',
'EUC-CN',
'gb2312',
'gb18030',
'hz-gb-2312',
'x-mac-chinesesimp',
'big5',
'x-Chinese-CNS',
'x-Chinese-Eten',
'x-mac-chinesetrad',
'cp866',
'koi8-r',
'koi8-u',
'x-mac-greek',
'windows-1253',
'ibm869',
'DOS-862',
'iso-8859-8-i',
'x-mac-hebrew',
'windows-1255',
'x-EBCDIC-Arabic',
'x-EBCDIC-CyrillicRussian',
'x-EBCDIC-CyrillicSerbianBulgarian',
'x-EBCDIC-DenmarkNorway',
'x-ebcdic-denmarknorway-euro',
'x-EBCDIC-FinlandSweden',
'x-ebcdic-finlandsweden-euro',
'x-ebcdic-finlandsweden-euro',
'x-iscii-as',
'unicode',
'unicodeFFFE',
'utf-7',
'utf-8',
'us-ascii',
'windows-1258',
'x-IA5',
'Windows-1252'
);
for each(var csStr:String in cs){
var info:String = _socket.readMultiByte(_socket.bytesAvailable, csStr);
temp = csStr + ":" + info;
if(info.length > 0)
dispatchEvent(new TextEvent(EVENT_ON_DATA_RECEIVED, false, false, temp) );
}
The only value that contains a value is ISO-8859-1. and and it looks like this:
The custom board is supposed to send something like : 0x40
So, not sure what is the best approach here (I know there are more charset I can try). Any ideas?

Are you trying to guess unknown encoding? Look at raw bytes that board sends to check whether they are bit-shifted.

Have you checked your settings - I'd suspect differing settings for parity bit.

Related

How to work around ImageJ run("HSB stack") error/ bug?

I am working on a macro for ImageJ. The goal is to take colour scans with several seeds on them and crop around the seeds to get several equally sized images with one seed on each.
This is the basic idea for the macro: prompt to select folder with scans (info about the seed is in the name of the image) > threshold to select seeds > crop around each seed on the original image > save all of the cropped images in a folder (name of the cropped images still containing the information of the name of the original image)
When I run the code below, I get an error for line 31: run("HSB stack");
The error informs me about supported conversions and shows that in order to run this command I need to start with an RGB image. However, according to Fiji > Image > Type, my images are RGBs. A coding error in that part also seems unlikely since it was written with the recording function in ImageJ.
Error message
According to what I found for the error, this seems to concern a recurring bug in the software, specific to the commands run("HSB stack") and run("RGB stack") in macros.
We have tried running this on ImageJ 2.3.0/1.53s as well as 1.53q on MacOS and Windows and always got the same problem.
If it is not a software problem, where is the error? Or if it is, do you have any suggestions for workarounds or a different program that could perform the same job?
The images I am working with are colour scans, 600dpi, white background with between 1 and 90 seeds on each scan. They are large tiff images (107.4 MB) but look like this:
Example scan image
I am not sure if it is helpful, but the code is below. There are probably still errors in the latter part that I could not yet get to because I can't get past the problem in line 31.
// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);
// Batch
for (i=0; j<list.length; i++) {
print(i + ":" + dir+list[i]};
// Open images
run("Bio-Formats Importer", "open=" + dir+list[i] + "color_mode=Default view =Hyperstack");
// Crop edge, set general cropping parameters, scale
makeRectangle(108, 60, 4908, 6888);
run("Crop");
main = getTitle():
default_crop_width = 350;
default_crop_height = 350;
run("Set Scale...", "distance=600 known=25.4 unit=mm global");
//Thresholding
run("Color Threshold...");
//Color Thresholder 2.3.0/1.53q
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB stack");
run("Convert Stack to images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=193;
filter[2]="pass";
for (i=0;j<3;i++){
selectWindow(""+i);
The problem lies in the fact that your image is a hyperstack, and the color thresholding doesn't know how to work with that.
There are a few options you could try: Open the image as an 8-bit RGB, e.g. via open(dir+list[i]); or split the channels of the hyperstack and threshold each separately. Based on your sample image, I assume the first option makes more sense.
The following is an edited version of your code that works for the sample that you've provided:
// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);
// Batch
for (i=0; i<list.length; i++)
{
if (!File.isDirectory(dir+list[i])) // Ignore directories such as processed_dir_name
{
print(i + ":" + dir+list[i]);
// Open images
open(dir+list[i]);
// Crop edge, set general cropping parameters, scale
makeRectangle(108, 60, 4908, 6888);
run("Crop");
main = getTitle();
default_crop_width = 350;
default_crop_height = 350;
run("Set Scale...", "distance=600 known=25.4 unit=mm global");
//Thresholding
//run("Color Threshold...");
//Color Thresholder 2.3.0/1.53q
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=193;
filter[2]="pass";
for (j=0;j<3;j++){
selectWindow(""+j);
}
}
}

"TLS support is not available" when creating GTlsClientConnection with libnice

I have working code where two peers are connecting over a relay server (coturn) and everything seems to be fine over pseudo-tcp. I've tested message exchange successfully with nice_agent_attach_recv() and nice_agent_get_io_stream().
But when I try to create a GTlsClientConnection I get back: 0:TLS support is not available
Here is some partial code:
if(!nice_agent_set_relay_info(agent, stream_id,
NICE_COMPONENT_TYPE_RTP,
"my.coturn.server",
5349, //tls-listener-port (I also tried the non tls port: 3478)
username.c_str(),
password.c_str(),
NICE_RELAY_TYPE_TURN_TCP))
{
printf("error setting up relay info\n");
}
...
//after state has changed to NICE_COMPONENT_STATE_READY
...
io_stream = nice_agent_get_io_stream (agent, stream_id, component_id);
input = g_io_stream_get_input_stream (G_IO_STREAM (io_stream));
output = g_io_stream_get_output_stream (G_IO_STREAM (io_stream));
GIOStream* tlsConnection = g_tls_client_connection_new
(G_IO_STREAM (io_stream), NULL, &error);
/////////////////////////
/// error == 0 (TLS support is not available)
I am new to libnice and glib. So, I may be missing something basic.
Probably need the glib-networking package installed.

AVAudioUnitEQ / .BandPass filter doesn't work

I can't get the AVAudioUnitEQ to work.
Here's a piece of code that should filter out everything except 659.255Hz +/-0.05 octaves:
// Create Audio Engine
var audioEngine = AVAudioEngine()
// Create Equalizer Node
var equalizerNode = AVAudioUnitEQ(numberOfBands: 1)
var epualizerParameters: AVAudioUnitEQFilterParameters = equalizerNode.bands.first as AVAudioUnitEQFilterParameters
epualizerParameters.filterType = .BandPass
epualizerParameters.frequency = 659.255
epualizerParameters.bandwidth = 0.05
epualizerParameters.bypass = false
audioEngine.attachNode(equalizerNode)
// Configure Audio Engine
var format = audioEngine.inputNode.inputFormatForBus(0)
audioEngine.connect(audioEngine.inputNode, to: equalizerNode, format: format)
audioEngine.connect(equalizerNode, to: audioEngine.outputNode, format: format)
// Start Audio Engine
var error:NSError?
audioEngine.startAndReturnError(&error)
However, when I run it, put on my headphones and sing into the microphone, I can hear myself loud and clear.
Now, according to Wikipedia, the Band Pass filter is:
... a device that passes frequencies within a certain range and
rejects (attenuates) frequencies outside that range.
What am I doing wrong? I want to filter out everything except given frequency range.
It was your EQ params.
I created a github project with sliders and switches. You can hear the difference.
Try it.
This works in my project which uses a playerNode.
var format = engine.mainMixerNode.outputFormatForBus(0)
engine.connect(playerNode, to: EQNode, format: format )
engine.connect(EQNode, to: engine.mainMixerNode, format: format)
I see you're using the engine's inputNode. Try swapping out these few lines (hook into the mixer instead of the outputNode) and let us know if it works.

Rails - How to test that ActionMailer sent a specific attachment?

In my ActionMailer::TestCase test, I'm expecting:
#expected.to = BuyadsproMailer.group_to(campaign.agency.users)
#expected.subject = "You submitted #{offer_log.total} worth of offers for #{offer_log.campaign.name} "
#expected.from = "BuyAds Pro <feedback#buyads.com>"
#expected.body = read_fixture('deliver_to_agency')
#expected.content_type = "multipart/mixed;\r\n boundary=\"something\""
#expected.attachments["#{offer_log.aws_key}.pdf"] = {
:mime_type => 'application/pdf',
:content => fake_pdf.body
}
and stub my mailer to get fake_pdf instead of a real PDF normally fetched from S3 so that I'm sure the bodies of the PDFs match.
However, I get this long error telling me that one email was expected but got a slightly different email:
<...Mime-Version: 1.0\r\nContent-Type: multipart/mixed\r\nContent-Transfer-Encoding: 7bit...> expected but was
<...Mime-Version: 1.0\r\nContent-Type: multipart/mixed;\r\n boundary=\"--==_mimepart_50f06fa9c06e1_118dd3fd552035ae03352b\";\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit...>
I'm not matching the charset or part-boundary of the generated email.
How do I define or stub this aspect of my expected emails?
Here's an example that I copied from my rspec test of a specific attachment, hope that it helps (mail can be creating by calling your mailer method or peeking at the deliveries array after calling .deliver):
mail.attachments.should have(1).attachment
attachment = mail.attachments[0]
attachment.should be_a_kind_of(Mail::Part)
attachment.content_type.should be_start_with('application/ics;')
attachment.filename.should == 'event.ics'
I had something similar where I wanted to check an attached csv's content. I needed something like this because it looks like \r got inserted for newlines:
expect(mail.attachments.first.body.encoded.gsub(/\r/, '')).to(
eq(
<<~CSV
"Foo","Bar"
"1","2"
CSV
)
)

How to convert PCM audio to TrueSpeech using NAudio

I am trying to convert a PCM 8 bit 8 KHz Mono file to DSP TrueSpeech 1 bit 8 kHz Mono using NAudio, and I get the following error:
A first chance exception of type 'NAudio.MmException' occurred in NAudio.dll
AcmNotPossible calling acmStreamOpen
I understand that there may be an intermediate step that I am missing -- any insight would be appreciated. Here is the code I am using:
WaveFormat outWaveFormat;
outWaveFormat = new TrueSpeechWaveFormat();
Debug.Print("Sample Rate: " + outWaveFormat.SampleRate); //displays "8000"
Debug.Print("Bit Rate: " + outWaveFormat.BitsPerSample); //displays "1"
FileInfo f = new FileInfo(inputFile);
String outputFileName = this.txtDest.Text + #"\" + f.Name;
using (WaveFileReader reader = new WaveFileReader(inputFile))
{
try
{
using (WaveStream convertedStream = new WaveFormatConversionStream (outWaveFormat, reader))
{
WaveFileWriter.CreateWaveFile(outputFileName, convertedStream);
}
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
}
Two reasons this might be happening:
you don't have a TrueSpeech encoder. I don't think newer versions of Windows include TrueSpeech anymore - it is effectively obsolete. You can run the NAudioDemo application to see what ACM codecs are on your machine.
your input format cannot convert to the target format in one step. Are you sure your input is PCM. Also I would expect that the TrueSpeech codec wants 16 bit input not 8 bit.
There is a third reason this can happen, although I don't think it affects TrueSpeech and that is that WaveFileWriter.CreateWaveFile assumes that AverageBytesPerSecond is an exact multiple of BlockAlign, which is not always true.