Can I use SpinalEnum as field in RegIf? - spinalhdl

I want to use SpinalEnum as RegIf field. Here is an example code, which doesn't seem to work:
object SourceEnum extends SpinalEnum {
val src1, src2, src3 = newElement()
}
...
val busif = BusInterface(...)
// Control Register
val ctrl = busif.newReg("Control register")
val source = ctrl.field(SourceEnum.C, RW, doc = "Data source")
It shows a following error during compilation: value C is not a member of object regiftest.SourceEnum. I was using the .C type "extraction" before, and it worked, but clearly it doesn't work in this case. What am I doing wrong?
Currently, as a workaround I'm using B(SourceEnum().getBitsWidth) with dest.assignFromBits(source), but it's not as elegant.

no, you can't put SpinalEnum in.
the RegIf REG.file() only accept HardType like
val busif = BusInterface(...)
// Control Register
val ctrl = busif.newReg("Control register")
val source = ctrl.field(Bits(8 bit), RW, doc = "Data source")
val reg1 = ctrl.field(UInt(8 bit), RW, doc = "....")
val reg2 = ctrl.field(SInt(8 bit), RW, doc = "....")
val reg3 = ctrl.field(Bool(), RW, doc = "....")
or old way
val reg1 = ctrl.field(8 bit, RW, doc = "....")
val reg2 = ctrl.field(8 bit, RW, doc = "....")
val reg3 = ctrl.field(1 bit, RW, doc = "....")
For details, please refer to
https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Libraries/regIf.html#

Related

Google sheets script - how to concate variable?

I have this code:
function _1() {
var aa = SpreadsheetApp.getActiveSpreadsheet();
var sheet = aa.getSheets()[0];
var cell = sheet.getRange("k1");
var cell = sheet.getvalue("a" + cell + ")");
};
In cell k1 there is a number (variable). I want to use this cell in my function, but its not work for me.
You entire code is correct, except last line:
var cell = sheet.getvalue("a" + cell + ")")
You don't need to import range value again in your getValue and it will cause error, and below is the correct execution by convert value to string (*remove ; after } ):
function test_1() {
var aa = SpreadsheetApp.getActiveSpreadsheet();
var sheet = aa.getSheets()[0];
var cell = sheet.getRange("B2").getValue();
cell = cell.toString() + "a"
Logger.log(cell);
}
Answer
getValue() does not take any input parameter. Join the strings later
Solution
I attach you a function that reads the number in B2 (X) and writes a string in AX.
function test_1() {
var aa = SpreadsheetApp.getActiveSpreadsheet();
var sheet = aa.getSheets()[0];
var B2 = sheet.getRange("B2").getValue();
var cell = "A" + B2.toString()
sheet.getRange(cell).setValue('test')
}
References
Range.getValue()
Range.setValue(value)

Expanding a SAP Tree

I'm using UFT (vbscript) to automate a process between SAP and a Web page. Using SAP transaction S_ALR_87013534, I have a piece of code in UFT that will expand the tree completely and extract the value associated with one of the order numbers:
set tree = SAPGuiSession("Session").SAPGuiWindow("Execute Drilldown Report").SAPGuiTree("TableTreeControl")
tree.OpenItemContextMenu "PRJ "&projNum,"PRJ "&projNum
tree.SelectMenuItemById "&EXPAND"
tree.SelectNode "PRJ "&projNum
colKey_plan1 = getColNameFromTitle(tree, "Plan 2--Overall")
rowContainingOrdNum = findBudget(tree, ordNum)
plannedProjectBudget = tree.Object.GetItemText(tree.Object.GetAllNodeKeys(rowContainingOrdNum(0)), colKey_plan1)
Function getColNameFromTitle(tree, title)
set colNames = tree.Object.GetColumnNames
For i = 1 To (colNames.length-1)
selectedColTitle = tree.Object.GetColumnTitleFromName(colNames(i))
If selectedColTitle = title Then
getColNameFromTitle = colNames(i)
Exit For
End If
Next
End Function
Function findBudget(tree, ordNum)
rowContainingOrdNum = Array()
Set columnNames = tree.Object.GetColumnNames()
set columnKeys = tree.Object.GetColumnCol(columnNames(0))
For i = 1 To (columnKeys.length-1)
If InStr(columnKeys(i), ordNum)>0 Then
AddItem rowContainingOrdNum, i
Exit For
End If
Next
findBudget = rowContainingOrdNum
End Function
Function AddItem(arr, val)
ReDim Preserve arr(UBound(arr) + 1)
arr(UBound(arr)) = val
AddItem = arr
End Function
This works perfectly, but when I use a different report, S_ALR_87013543, it's still recognised as a tree but the above code doesn't work as there is no EXPAND option at the Object heading. I'm not very familiar with SAP and all their trees and how to use automation with it, so any guidance or tips are appreciated.
Left is the report I need to expand, and right is the report the code works with:
Solution:
Set TreeObj = SAPGuiSession("Session").SAPGuiWindow("Actual/Plan/Variance").SAPGuiTree("TableTreeControl").Object
Set AllValues = TreeObj.GetAllNodeKeys
Count = AllValues.Count
Found = 0
For i = 0 to Count-1
NodeText = TreeObj.GetNodeTextByKey(AllValues(i))
If NodeText = WBSelement Then
Found = 1
Exit For
End if
Next
If Found = 1 Then
SAPGuiSession("Session").SAPGuiWindow("Actual/Plan/Variance").SAPGuiTree("TableTreeControl").SelectNode WBS
End If

Kotlin: strip first and last character

In Kotlin, I need to strip the first and last characters from a string. This seems to be getting compile errors:
val MyPiece = str.substring(0, str.length - 1)
What's wrong here?
You can also do:
val str = "hello"
val myPiece = str.drop(1).dropLast(1)
println(myPiece)
You can try this one:
val str = "myText"
var myPiece = str.substring(1, str.length -1)
print(myPiece)

issues with entering variables into dictionary

here's my code, or rather the part of the code i'm having issues with.
the problem is at the if expression, where i'm trying to check whether a value is already in a dictionary (the actual code is in a larger while loop, used for a user interface), but when it runs the second time round it will always go into the else section, i'm assuming because of the variable name already being present in the dictionary.
Dict1 = {#empty dictionary}
completedList = (#list variable containing “true” and “false”)
name = input(“enter your name”)
score = completedList.count("true")
callback = 'cont'
while callback == 'cont':
if name not in dict1 == True:
dict1 = [name] = score
callback = ""
else:
print("that name is already in use \n please choose another")
name = input("enter a name")
I'm a student, so the simpler the code the better.
dict1 = {'er'}
completedLis=()
name = input("enter your name")
score = completedLis.count("true")
callback = 'cont'
while (callback == 'cont'):
if (name not in dict1):
dict1 = name = score
callback = ''
else:
print("that name is already in use \n please choose another")
name = input("enter a name")
I hope this solves ur problem if u type er(dict1='er')it will go to else or if u type anything else it will work

C# office 2010 automation

i'm trying to make a program that inserts data into specific places in existing word document and saves a copy of it.
and i have no clue how to do it , and i cant find any good resource on office 2010 automating.
can anyone point me in the right direction and/or give me some examples.
thanks in advance.
found a solution will add an answer later on
Here is how i did it , it may not be the best way , but its working !
add references to the office interop
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
//defines new excel and workd apps
var ap = new Word.Application();
var excelApp = new Excel.Application();
// defines new excel worksheet & workbooks
Excel.Workbook exBook;
Excel.Worksheet xlWorkSheet;
// should the excell/word apps be visible ?
excelApp.Visible = false;
ap.Visible = false;
//defining the index numbers of our content controls that are in the word template
// index numbers start from 1 and are numbered by order of creation
object Price, Name, address;
Price = 1;
Name = 2;
address = 3;
// here we open the excell file
exBook = excelApp.Workbooks.Open(#"C:\test.xls");
// and we open the first worksheet
xlWorkSheet = exBook.Worksheets.get_Item(1);
Excel.Range range ;
//here we select the first worksheet and make it active
Excel._Worksheet workSheet = (Excel.Worksheet) excelApp.ActiveSheet;
//we open the word document
var doc = ap.Documents.Open(#"C:\test.dotx", ReadOnly: false, Visible: false);
// and we assign the content controls
var dPrice = doc.ContentControls.get_Item(ref Price);
var dName = doc.ContentControls.get_Item(ref Name);
var dAddress = doc.ContentControls.get_Item(ref address);
doc.Activate();
range = xlWorkSheet.UsedRange;
// here we define the columns that we are going to select
object t, P , E , K, N,M,J;
P = "P";
E = "E";
K = "K";
J = "J";
N = "N";
M = "M";
// and here we loop trought the rows of the excell worksheet
// IMPORTANT! excell rows count starts from 1 and not from 0 !
for (int i =1; i< Convert.ToInt16(Settings1.Default.copies) ;i++)
{
t = i;
// here we get the value if cell t(1..2..3..etc), P
var dummy = (range.Cells[t, P] as Excel.Range).Value2;
// here we insert the content of the cell to the content control
dPrice.Range.Text = ": " + Convert.ToString(dummy) + " лв";
dName.Range.Text = ": " + (string)(range.Cells[t, E] as Excel.Range).Value2;
// same thing here
var city = (string) (range.Cells[t, J] as Excel.Range).Value2;
var address1 = (string) (range.Cells[t, K] as Excel.Range).Value2;
var city2 = (string) (range.Cells[t, M] as Excel.Range).Value2;
var address2 = (string) (range.Cells[t,N] as Excel.Range).Value2;
if (!string.IsNullOrEmpty(city2) && city2 != " " && !string.IsNullOrEmpty(address2) && address2 != " ")
{
dAddress.Range.Text = ": " +city.Normalize() + " " + address1.Normalize() + " , " + city2.Normalize() + " " + address2.Normalize() ;
}
else
{
dAddress.Range.Text = ": " + city.Normalize() + " " + address1.Normalize();
}
try
{
//here we try to save the word document as a pdf file
object name = #"C:\t\test"+i+".pdf";
object FileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref name, ref FileFormat);
}
catch (Exception ex)
{
MessageBox.Show("Exception Caught: " + ex.Message +" source "+ ex.Source.ToString());
}
}
// here quit word without saving the changes to the template
ap.Quit(SaveChanges: false, OriginalFormat: false, RouteDocument: false);
excelApp.Quit();
// and we release the objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(ap);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
i hope this was helpful to someone :)