I would like to control a NAO robot with a remote control by using C#.
There is only an example in Python on the Aldebaran website.
Unfortunately, I haven't learnt Python.
Could anyone help me convert this Python example into C#?
The following links may be helpful to you.
https://community.aldebaran-robotics.com/doc/1-14/naoqi/sensors/alinfrared-tuto.html#alinfrared-tuto
https://community.aldebaran-robotics.com/doc/1-14/naoqi/sensors/alinfrared-api.html
# -*- encoding: UTF-8 -*-
"""
Receive and display remote buttons event:
"""
import naoqi
import time
# create python module
class myModule(naoqi.ALModule):
def pythondatachanged(self, strVarName, value, strMessage):
"""callback when data change"""
print "Data changed on", strVarName, ": ", value, " ", strMessage
# call method
try:
lircProxy = naoqi.ALProxy("ALInfrared")
lircProxy.initReception(repeatThreshold = 10)
pythonModule = myModule("pythonModule")
memProxy = naoqi.ALProxy("ALMemory")
memProxy.subscribeToEvent("InfraRedRemoteKeyReceived", "pythonModule",
"pythondatachanged")
except Exception, e:
print "error"
print e
exit(1)
time.sleep(10)
exit(0)
Related
I have an Epson TM-T88VI printer and use the Microsoft.PointOfService.PosPrinter in C# for printing.
Using the following function i get a strange output printed:
public static void printerTestFunction2(string printerName)
{
PosExplorer explorer = new PosExplorer();
DeviceInfo di = explorer.GetDevice("PosPrinter", printerName);
PosPrinter printer = (PosPrinter)explorer.CreateInstance(di);
printer.Open();
printer.Claim(10000);
printer.DeviceEnabled = true;
printer.AsyncMode = false;
string init = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, 64 });
string totalCut = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, 105 });
string cmd = init + init + "A€A\nB€B\n" + init + "C€C\nD€D\n\n\n\n\n\n\n" + totalCut;
printer.PrintNormal(PrinterStation.Receipt, cmd);
}
The output is:
A€A
B€B
CFC
DFD
So the € symbol is printed as a strange "F" symbol (seems like the F is lower than the normal characters).
The paper is cut correctly.
I also have tested different constellations. It seems that the "€" sign is only printed before the first init command which is send to the printer after at least one row has been printed out. (I can send multiple init commands at the beginning - the € is printed. If i send the init after some chars have been printed, the "F" will appear instead of the "€").
If I restart my program, the "€" is again printed correctly, but if i send the init command it will be printed as "F" again.
What is the reason that the "€" symbol is only printed before the third init command?
Is there anything wrong with my code or do i miss a setting?
The reason why letters like F are printed is because the printer is in the initialized state, code page 437.
Look at the letters in the following material at 213 in decimal and 0xD5 in hexadecimal.
Page 0 [PC437: USA, Standard Europe]
Page 19 [PC858: Euro]
The POS for.NET service object internally manages code page settings according to the value of CharacterSet property.
If the application arbitrarily sends initialization commands to the printer, the service object's management information may be inconsistent and the printer may print incorrectly.
If you are using POS for.NET (including OPOS/JavaPOS), you should not use the initialization command (ESC#) or similar commands to change the mode or settings.
In that sense, instead of sending the paper cut also directly the ESC i({ 27, 105 }) command, call the CutPaper method or put the POSPrinter paper cut escape sequence (ESC|P) defined in UnifiedPOS in the print request string.
The following code works perfectly without flaw:
public partial class MainForm : Form
{
string pyInterp = File.ReadAllText(Directory.GetCurrentDirectory() + #"\config\pathToPythonInterpreter.txt");
string pyWeather = #"C:\getWeather.py";
public MainForm()
{
InitializeComponent();
UpdateWeather();
}
public void UpdateWeather()
{
labelWeather.Text = PySharp.ExecutePy(pyInterp, pyWeather);
}
}
However, when I change the path to getWeather.py to not be in an arbitrary random location, like this:
string pyWeather = Directory.GetCurrentDirectory() + #"\scripts\getWeather.py";
Then my program no longer obtains the script's output. The script still works: I launched it using IDLE and it completed its function properly. When I call it using C#, the console opens, yet no output is obtained.
The Python script is the following:
from requests import get
from bs4 import BeautifulSoup as soup
r = get("http://www.ilmateenistus.ee/ilm/prognoosid/4-oopaeva-prognoos/")
parsed = soup(r.content, "html.parser")
container = parsed.find("div",{"class":"point kuusiku"})
print(str(container["data-title"]))
(It webscrapes my local weather)
PySharp.ExecutePy() can be viewed here
By far the strangest bug I've ever encountered. Any ideas?
EDIT 1: It seems that C# is indeed reading something from the script. It just appears that this something is.. nothing. I gave the label a default sample text, and after running the program, the label's text is simply changed to an empty string. Hope this incredible discovery helps somehow.
EDIT 2: The program fails to call the script correctly when its filepath contains spaces. For example:
C:\foo bar\testing\pyWeather.py
does not work!
Try surrounding the path that contains spaces with 2 double quotes.
For e.g.
string pyWeather = #"""C:\Users\[myname]\Documents\Visual Studio 2017\Projects\testing\testing\scripts\getWeather.py""";
Similarly, you can do string pyWeather = Directory.GetCurrentDirectory() + #"\scripts\getWeather.py"; followed by pyWeather = "\"" + pyWeather + "\"";.
I would want you to return the answer instead of printing. Printer is an I/O based solution to display. So it will work super fine with IDLE however it may not return results as you expected. I strongly believe this will solve your problem.
instead of printing please try return. I can give more support after trying this.
return(str(container["data-title"]))
Is it possible to ask Excel to start a C# method?
How would you implement such a call in Excel?
(i.e. instead of programming in VB, I would like to program in C#)
I can imagine using a VB-macro to start a C# application in the background but maybe you know a nicer way?
For example, the C#-code shall be executed upon a click in a particular Excel cell.
Well you could open a program via VBA. This VBA script gets called by clicking on the Excel-Cell:
var Path = "MYPROGRAMPATH"
var Argument = "MYARGUMENT"
x = Shell("""" & Path & """ """ & Argument & """", vbNormalFocus)
To react on a cell change, use the following event:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'YOUR CODE
End Sub
Then program your C# application and let it determine the arguments.
Your program should react according to the filtered arguments.
This can be done with the Environment.GetCommandLineArgs-Method.
public static void Main()
{
Console.WriteLine();
// Invoke this sample with an arbitrary set of command line arguments.
String[] arguments = Environment.GetCommandLineArgs();
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));
//Handling of arguments here, switch-case, if-else, ...
}
I've found a solution to the VBA macro:
Sub Button1_Click()
Dim pathStr As String
Dim argumentStr As String
pathStr = "C:/Users/.../Desktop/temp/Trial02.exe"
argumentStr = "Any argument string"
Call Shell("""" & pathStr & """ """ & argumentStr & """", vbNormalFocus)
End Sub
I'm trying to create a clearcase dynamic view using CAL in C# using the following code.
private static ClearCase.ClearTool ct;
string viewName = "tmp_view";
string cmd = "mkview –tag "+ viewName + " –stream " + selectedStream +"#"+ projectVob + " \\\\<Network Shared Path>\\"+ viewName +".vws";
ct.CmdExec(cmd);
On execution, ct.CmdExec method throws exception saying viewTag must be specified.
For the same cmd string I'm able to create a view using cleartool command prompt.
Can you please tell me why I'm unable to create a view in C#?
It is possible that you didn't used -tag but –tag: replace '–' (minus) by '-' (hyphen minus).
Note: same for –stream: use -stream.
(plus , minus , hyphen-minus)
See What's the toughest bug you ever found and fixed? :
"Hyphen-minus" is the regular familiar character on keyboards, ASCII 45 and U+002D, (ab)used in both "5-4=1" and "vice-versa".
The actual minus sign, which is longer, is U+2212 and is not in ASCII.
It is typical of IBM documentation which, unfortunately, use minus (the long '–'): any copy-paste coming from their page doesn't work immediately.
I have a asp.net and c# project.
I need to print this string out, i get it like this from the server:
Working...: 0/0\r\nNavigating: 0/0
It should be printed out in 2 separate lines (using the \r\n), shouldn't it be doing that automatically?
Am i doing something wrong?
I cant change the string but the way i use it, is:
I have a EO progress bar that i send a message like this:
_progressBar.UpdateProgress(_count, progress.Message);
And it displays the message under the progressBar.
The message is the string i posted on top.
Thanks
It seems like your string might contain #"\r\n" instead of "\r\n", case in which you'd have to parse the escape characters yourself.
For example, to replace backslash-r by CR and backslash-n by LF (not the most efficient way to do it):
string s0 = #"A\r\nB"; // s0 would print as: A\r\nB
string s = s0.Replace(#"\r","\r").Replace(#"\n","\n");
Now s contains:
A
B
use <br/> - that is a line break in HTML...
EDIT - as per comment:
string X = #"Working...: 0/0\r\nNavigating: 0/0";
string Y = X.Replace ( #"\r\n", #"<br/>" ); // Result is Working...: 0/0<br/>Navigating: 0/0
The server has to send to the client data that the latter understands. JSON, HTML, XML or whatever data type you're working with.
From the client's point of view \r\n is just a string like any other. In this case you may want to send something like:
Working...: 0/0<br/>Navigating: 0/0
And print it has HTML.
You probably are sending a backslash followed by an n or r and not a \r or \n.
If so you have to parse them yourself or get the output to be \r and \n
Yes it is automatic.
using System;
public class Test
{
public static void Main(string[] args)
{
string mesg = "Working...: 0/0\r\nNavigating: 0/0";
Console.WriteLine(mesg);
}
}
C:\temp>csc Test.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.
Copyright (C) Microsoft Corporation. All rights reserved
C:\temp>Test
Working...: 0/0
Navigating: 0/0
C:\temp